local extension = Package("fengqi_standard")
extension.extensionName = "aaa_fengqi"

local U = require "packages/utility/utility"
--local RUtil = require "packages/rfenghou/utility/rfenghou_util"

Fk:loadTranslationTable{
  ["fengqi_standard"] = "标准",
}

-- 由于主服的冰伤害改弃牌的效果只有冰杀才能触发，此处改为非冰杀也能触发，哈哈！
local IceDamageSkill = fk.CreateTriggerSkill{
  name = "efengqi_ice_damage_skill",
  priority = 0.1,
  global = true,
  mute = true,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and data.damageType == fk.IceDamage and
    not (data.card and data.card.name == "ice__slash")
    and not data.chain and not data.to:isNude()
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#efengqi_ice_damage-invoke:"..data.to.id.."::"..data.damage)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    for i = 1, 2 do
      if to:isNude() then break end
      local card = room:askForCardChosen(player, to, "he", self.name)
      room:throwCard({card}, self.name, to, player)
    end
    return true
  end
}
Fk:addSkill(IceDamageSkill)
Fk:loadTranslationTable{
  ["efengqi_ice_damage_skill"] = "冰伤",
  ["#efengqi_ice_damage-invoke"] = "你可以将对 %src 造成的 %arg 冰伤害改为依次弃置2张牌",
}

local caocao = General(extension, "efengqi__caocao", "wei", 4)
local efengqi__jianxiong_card_skill = fk.CreateActiveSkill{
  name = "efengqi__jianxiong_card_skill",
  target_num = 1,
  mod_target_filter = Util.TrueFunc,
  target_filter = Util.TargetFilter,
  on_effect = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.to)
    if not to.dead then
      room:damage({
        from = from,
        to = to,
        card = effect.card,
        damage = 1,
        skillName = Fk:cloneCard(effect.card.name).skill.name
      })
    end
  end,
}
efengqi__jianxiong_card_skill.cardSkill = true
local jianxiong = fk.CreateTriggerSkill{
  name = "efengqi__jianxiong",
  anim_type = "masochism",
  events = {fk.Damaged, fk.TargetConfirmed},
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.Damaged then return true end
      return data.from and data.from ~= player.id and data.card:isCommonTrick()
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.Damaged then
      return player.room:askForSkillInvoke(player, self.name, data, "#efengqi__jianxiong-get")
    else
      return player.room:askForSkillInvoke(player, self.name, data, "#efengqi__jianxiong-trick:::"..data.card:toLogString())
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      if data.card and U.hasFullRealCard(room, data.card) then
        room:obtainCard(player.id, data.card, true, fk.ReasonJustMove)
      end
      if not player.dead then
        player:drawCards(1, self.name)
      end
    else
      data.extra_data = data.extra_data or {}
      data.extra_data.efengqi__jianxiongTos = data.extra_data.efengqi__jianxiongTos or {}
      table.insertIfNeed(data.extra_data.efengqi__jianxiongTos, player.id)
    end
  end,

  refresh_events = {fk.PreCardEffect},
  can_refresh = function(self, event, target, player, data)
    return data.to == player.id and
    data.extra_data and data.extra_data.efengqi__jianxiongTos and table.contains(data.extra_data.efengqi__jianxiongTos, data.to)
  end,
  on_refresh = function(self, event, target, player, data)
    local card = data.card:clone()
    local c = table.simpleClone(data.card)
    for k, v in pairs(c) do
      card[k] = v
    end
    card.skill = efengqi__jianxiong_card_skill
    data.card = card
  end,
}
caocao:addSkill(jianxiong)

local zhujiu = fk.CreateTriggerSkill{
  name = "efengqi__zhujiu",
  anim_type = "support",
  events = {fk.TurnStart},
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      return not player:isNude() and table.find(player.room.alive_players, function (p) return p.hp == 1 end)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local _,dat = player.room:askForUseActiveSkill(player, "efengqi__zhujiu_active", "#efengqi__zhujiu", true)
    if dat then
      player.room:sortPlayersByAction(dat.targets)
      self.cost_data = {tos = dat.targets, cards = dat.cards}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data.cards, self.name, player, player)
    for _, to in ipairs(table.map(self.cost_data.tos, Util.Id2PlayerMapper)) do
      if not to.dead then
        room:recover { num = 1, skillName = self.name, who = to, recoverBy = player }
      end
    end
  end,
}
caocao:addSkill(zhujiu)
local zhujiu_active = fk.CreateActiveSkill{
  name = "efengqi__zhujiu_active",
  min_target_num = 1,
  card_filter = function(self, to_select, selected)
    return Fk:getCardById(to_select).suit == Card.Club and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    local to = Fk:currentRoom():getPlayerById(to_select)
    return #selected < #selected_cards and to.hp == 1 and to:isWounded()
  end,
}
Fk:addSkill(zhujiu_active)


local huibian = fk.CreateActiveSkill{
  name = "efengqi__huibian$",
  anim_type = "offensive",
  frequency = Skill.Limited,
  card_num = 0,
  min_target_num = 1,
  prompt = "#efengqi__huibian",
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected < 2 and not Self:isProhibited(Fk:currentRoom():getPlayerById(to_select), Fk:cloneCard("slash"))
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    and not player:prohibitUse(Fk:cloneCard("slash"))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local card = Fk:cloneCard("slash")
    card.skillName = self.name
    card:addSubcards(room:getNCards(2))
    room:useCard{
      from = player.id,
      tos = table.map(effect.tos, function(p) return {p} end),
      card = card,
      extraUse = true,
    }
    if table.find(effect.tos, function(id) return room:getPlayerById(id).kingdom == "wei" end) then
      room:setPlayerMark(player, "efengqi__huibian_mark", 1)
    end
  end,
}
local huibian_trigger = fk.CreateTriggerSkill{
  name = "#efengqi__huibian_trigger",
  refresh_events = {fk.TurnStart},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("efengqi__huibian_mark") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "efengqi__huibian_mark", 0)
    player:setSkillUseHistory(huibian.name, 0, Player.HistoryGame)
  end,
}
huibian:addRelatedSkill(huibian_trigger)
caocao:addSkill(huibian)


--[[
local weiwu = fk.CreateTriggerSkill{
  name = "efengqi__weiwu$",
  events = {fk.TurnEnd},
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skills = room:getTag("efengqi__weiwu_skills")
    if skills == nil then
      skills = {}
      for _, gname in ipairs(Fk.lords) do
        local g = Fk.generals[gname]
        if Fk:canUseGeneral(gname) then
          for _, s in ipairs(g:getSkillNameList(true)) do
            if Fk.skills[s].lordSkill then
              table.insert(skills, s)
            end
          end
        end
      end
      room:setTag("efengqi__weiwu_skills", skills)
    end
    skills = table.filter(skills, function(s) return not player:hasSkill(s, true) end)
    if #skills == 0 or room:askForChoice(player, {"#efengqi__weiwu_lord", "#efengqi__weiwu_change"}, self.name) == "#efengqi__weiwu_change" then
      local p = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper),
        1, 1, "#efengqi__weiwu-choose", self.name, false)[1]
      local victim = room:getPlayerById(p)
      local kingdoms = table.simpleClone(Fk.kingdoms)
      table.removeOne(kingdoms, victim.kingdom)
      local choice = room:askForChoice(player, kingdoms, self.name, nil, false, Fk.kingdoms)
      room:changeKingdom(victim, choice, true)
    else
      local result = room:askForChoice(player, table.random(skills, 3), self.name, nil, true)
      room:handleAddLoseSkills(player, result)
    end
  end,
}
caocao:addSkill(weiwu)
--]]

Fk:loadTranslationTable{
  ["efengqi__caocao"] = "曹操",
  ["#efengqi__caocao"] = "魏武帝",
  ["designer:efengqi__caocao"] = "伶伶",
  ["illustrator:efengqi__caocao"] = "",

  ["efengqi__jianxiong"] = "奸雄",
  [":efengqi__jianxiong"] = "当你受到伤害后，你可以获得对你造成伤害的牌并摸一张牌。当你成为其他角色的普通锦囊牌的目标后，你可以将效果改为对你造成1点伤害。",
  ["#efengqi__jianxiong-get"] = "奸雄：你可以获得对你造成伤害的牌并摸一张牌",
  ["#efengqi__jianxiong-trick"] = "奸雄：你可以将%arg对你效果改为造成1点伤害",

  ["efengqi__huibian"] = "挥鞭",
  [":efengqi__huibian"] = "主公技，限定技，出牌阶段，你可以将牌堆顶的牌当【杀】对两名角色使用，若含魏势力，你的下个回合开始时，此技能视为未发动。",
  ["#efengqi__huibian"] = "挥鞭:将牌堆顶两张牌当【杀】对两名角色使用，若含魏势力，下回合重置",

  ["efengqi__zhujiu"] = "煮酒",
  [":efengqi__zhujiu"] = "回合开始时，你可以弃置任意张♣牌，令等量名体力为1的角色各回复1点体力。",
  ["#efengqi__zhujiu"] = "煮酒：你可以弃置任意张♣牌，令等量名体力为1的角色各回复1点体力",
  ["efengqi__zhujiu_active"] = "煮酒",
  --[[
  ["efengqi__weiwu"] = "魏武",
  [":efengqi__weiwu"] = "主公技，回合结束时，你可以选择：1.发现一个主公技；2.变更一名角色势力。",
  ["#efengqi__weiwu_lord"] = "发现一个主公技",
  ["#efengqi__weiwu_change"] = "变更一名角色势力",
  ["#efengqi__weiwu-choose"] = "魏武，选择一名角色，变更其势力",
  --]]

  ["$efengqi__jianxiong1"] = "燕雀，安知鸿鹄之志！",
  ["$efengqi__jianxiong2"] = "夫英雄者，胸怀大志，腹有良谋！",
  ["$efengqi__huibian1"] = "吾任天下之智力，以道御之，无所不可。",
  ["$efengqi__huibian2"] = "青青子衿，悠悠我心，但为君故，沉吟至今。",
  ["~efengqi__caocao"] = "霸业未成！未成啊！",
}


local simayi = General(extension, "efengqi__simayi", "wei", 4)

local fankui = fk.CreateTriggerSkill{
  name = "efengqi__fankui",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from and not data.from.dead and not data.from:isNude()
  end,
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      if i > 1 and (self.cancel_cost or data.from.dead or data.from:isNude() or not player:hasSkill(self)) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askForSkillInvoke(player, self.name, data, "#efengqi__fankui-invoke::"..data.from.id) then
      self.cost_data = {tos = {data.from.id}}
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cid = room:askForCardChosen(player, data.from, "he", self.name)
    room:obtainCard(player, cid, false, fk.ReasonPrey, player.id, self.name)
    local card = Fk:getCardById(cid)
    if not player.dead and table.contains(player:getCardIds("h"), cid) and card.type == Card.TypeEquip then
      local targets = table.filter(room.alive_players, function (p) return p:canUseTo(card, p) end)
      if #targets == 0 then return false end
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1,
      "#efengqi__fankui-use:::"..card:toLogString(), self.name, true)
      if #tos > 0 then
        room:useCard{from = tos[1], tos = {tos}, card = card}
      end
    end
  end
}
simayi:addSkill(fankui)

local guicai = fk.CreateTriggerSkill{
  name = "efengqi__guicai",
  anim_type = "control",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p) return not p:isNude() end)
    if #targets == 0 then return false end
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1,
    "#efengqi__guicai-choose::"..target.id..":"..data.reason..":"..data.card:toLogString(), self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local cid = room:askForCardChosen(player, to, "he", self.name)
    local card = Fk:getCardById(cid)
    room:delay(300)
    room:moveCards{
      ids = {cid},
      from = to.id,
      toArea = Card.Processing,
      moveReason = fk.ReasonResonpse,
      skillName = self.name,
      proposer = player.id,
    }
    room:sendFootnote({cid}, {
      type = "##ResponsePlayCard",
      from = player.id,
    })
    local oldJudge = data.card
    data.card = card
    room:sendLog{
      type = "#ChangedJudge",
      from = player.id,
      to = { data.who.id },
      arg2 = card:toLogString(),
      arg = self.name,
    }
    Fk:filterCard(data.card.id, data.who, data)
    room:delay(500)
    room:moveCards{
      ids = { oldJudge:getEffectiveId() },
      toArea = Card.DiscardPile,
      moveReason =  fk.ReasonJudge,
      skillName = self.name,
    }
    if not to.dead and not player.dead and room:askForSkillInvoke(to, self.name, nil, "#efengqi__guicai-damage:"..player.id) then
      room:doIndicate(to.id, {player.id})
      room:damage { from = to, to = player, damage = 1, skillName = self.name }
    end
  end,
}
simayi:addSkill(guicai)

Fk:loadTranslationTable{
  ["efengqi__simayi"] = "司马懿",
  ["#efengqi__simayi"] = "狼顾之鬼",
  ["designer:efengqi__simayi"] = "食马者",
  ["illustrator:efengqi__simayi"] = "木美人",

  ["efengqi__fankui"] = "反馈",
  [":efengqi__fankui"] = "每当你受到1点伤害后，可以获得伤害来源一张牌；若为装备牌，你可以令一名角色使用之。",
  ["#efengqi__fankui-invoke"] = "反馈：你可以获得 %dest 一张牌！",
  ["#efengqi__fankui-use"] = "反馈：你可以令一名角色使用 %arg！",

  ["efengqi__guicai"] = "鬼才",
  [":efengqi__guicai"] = "当一名角色的判定牌生效前，你可以打出一名角色一张牌替代之，然后其可以对你造成1点伤害。",
  ["#efengqi__guicai-choose"] = "鬼才：你可以打出一名角色的一张牌代替 %dest 进行“%arg”判定的判定牌%arg2",
  ["#efengqi__guicai-damage"] = "鬼才：你可以对 %src 造成1点伤害",

  ["$efengqi__guicai1"] = "天命难违？哈哈哈哈哈……",
  ["$efengqi__guicai2"] = "才通天地，逆天改命！",
  ["$efengqi__fankui1"] = "哼，自作孽不可活！",
  ["$efengqi__fankui2"] = "哼，正中下怀！",
  ["~efengqi__simayi"] = "我的气数，就到这里了么？",
}

local guojia = General(extension, "efengqi__guojia", "wei", 3)

local tiandu = fk.CreateTriggerSkill{
  name = "efengqi__tiandu",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.FinishJudge},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    player.room:damage{
      to = player,
      damage = 1,
      skillName = self.name,
      isVirtualDMG = true,
    }
  end,
}
guojia:addSkill(tiandu)

local yiji = fk.CreateTriggerSkill{
  name = "efengqi__yiji",
  anim_type = "masochism",
  events = {fk.Damaged, fk.Death},
  can_trigger = function (self, event, target, player, data)
    if target == player then
      return player:hasSkill(self, false, true)
    end
  end,
  on_trigger = function(self, event, target, player, data)
    if event == fk.Death then
      return self:doCost(event, target, player, data)
    end
    self.cancel_cost = false
    for _ = 1, data.damage do
      if self.cancel_cost or not player:hasSkill(self, false, true) then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askForSkillInvoke(player, self.name, data) then
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = room:askForChoices(player, {"efengqi__yiji_watch", "draw2", "efengqi__yiji_give"}, 2, 2, self.name, nil, false)
    if table.contains(choices, "efengqi__yiji_watch") then
      room:askForGuanxing(player, room:getNCards(2), nil, nil, self.name)
    end
    if table.contains(choices, "draw2") then
      player:drawCards(2, self.name)
    end
    if table.contains(choices, "efengqi__yiji_give") then
      local num = math.min(2, #player:getCardIds("he"))
      if num > 0 then
        room:askForYiji(player, player:getCardIds("he"), room:getOtherPlayers(player), self.name, num, num)
      end
    end
  end,
}
guojia:addSkill(yiji)

Fk:loadTranslationTable{
  ["efengqi__guojia"] = "郭嘉",
  ["#efengqi__guojia"] = "",
  ["designer:efengqi__guojia"] = "屑",
  ["illustrator:efengqi__guojia"] = "云涯",

  ["efengqi__tiandu"] = "天妒",
  [":efengqi__tiandu"] = "锁定技，当你的判定牌生效后，你视为受到过1点伤害。",

  -- 注意：要求死亡伤害也能发动 
  ["efengqi__yiji"] = "遗计",
  [":efengqi__yiji"] = "当你受到1点伤害后或死亡时，你可以执行不同的两项：1.卜算2；2.摸两张牌；3.分配两张牌。",
  ["efengqi__yiji_watch"] = "卜算2",
  ["efengqi__yiji_give"] = "分配两张牌",

  ["$efengqi__tiandu1"] = "那，就这样吧。",
  ["$efengqi__tiandu2"] = "天意如此。",
  ["$efengqi__yiji1"] = "锦囊妙策，终定社稷。",
  ["$efengqi__yiji2"] = "依此计行，辽东可定。",
  ["~efengqi__guojia"] = "咳，咳咳咳。",
}

local zhenji = General(extension, "efengqi__zhenji", "wei", 3, 3, General.Female)

local luoshen = fk.CreateTriggerSkill{
  name = "efengqi__luoshen",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerHand then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|spade,club",
      skipDrop = true,
    }
    room:judge(judge)
    if player.dead or not judge.card then return end
    if judge.card.color == Card.Black then
      if room:getCardArea(judge.card) == Card.Processing then
        local to = player
        local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
        "#efengqi__luoshen-give:::"..judge.card:toLogString(), self.name, true)
        if #tos > 0 then
          to = room:getPlayerById(tos[1])
        end
        room:obtainCard(to, judge.card, true, fk.ReasonGive, player.id, self.name,
        to == player and "@@efengqi__luoshen-inhand-turn" or nil)
      end
    else
      room:invalidateSkill(player, self.name, "-turn")
      if room:getCardArea(judge.card) == Card.Processing then
        room:moveCardTo(judge.card, Card.DiscardPile, nil, fk.ReasonJudge)
      end
    end
  end,
}

local luoshen_maxcards = fk.CreateMaxCardsSkill{
  name = "#efengqi__luoshen_maxcards",
  exclude_from = function(self, player, card)
    return card:getMark("@@efengqi__luoshen-inhand-turn") > 0
  end,
}
luoshen:addRelatedSkill(luoshen_maxcards)

zhenji:addSkill(luoshen)

local qingguo = fk.CreateViewAsSkill{
  name = "efengqi__qingguo",
  anim_type = "defensive",
  pattern = "jink",
  prompt = "#efengqi__qingguo",
  frequency = Skill.Compulsory,
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    return Fk:getCardById(to_select).color == Card.Black and table.contains(Self:getHandlyIds(true), to_select)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local c = Fk:cloneCard("jink")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}
local qingguo_trigger = fk.CreateTriggerSkill{
  name = "#efengqi__qingguo_trigger",
  anim_type = "drawcard",
  main_skill = qingguo,
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(qingguo) and player:getMark("efengqi__qingguo-turn") < 3 then
      return data.to > 1 and data.to < 8
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "efengqi__qingguo-turn", 1)
    player:drawCards(1, qingguo.name)
    return true
  end,
}
qingguo:addRelatedSkill(qingguo_trigger)
zhenji:addSkill(qingguo)

Fk:loadTranslationTable{
  ["efengqi__zhenji"] = "甄姬",
  ["#efengqi__zhenji"] = "",
  ["designer:efengqi__zhenji"] = "屑",
  ["illustrator:efengqi__zhenji"] = "官方",

  ["efengqi__luoshen"] = "洛神",
  [":efengqi__luoshen"] = "当你获得牌后，你可以进行一次判定。若结果为黑，你分配之，若不为黑则本回合此技能失效。你以此获得的牌本回合不计上限。",
  ["#efengqi__luoshen-give"] = "洛神：令一名角色获得%arg，点取消给自己",
  ["@@efengqi__luoshen-inhand-turn"] = "洛神",

  ["efengqi__qingguo"] = "倾国",
  [":efengqi__qingguo"] = "锁定技，你的前三个阶段改为摸一张牌。你可以将黑色手牌当【闪】使用或打出。",
  ["#efengqi__qingguo"] = "倾国：你可以将黑色手牌当【闪】使用或打出",
  ["#efengqi__qingguo_trigger"] = "倾国",

  ["$efengqi__luoshen1"] = "髣髴兮若轻云之蔽月。",
  ["$efengqi__luoshen2"] = "飘飖兮若流风之回雪。",
  ["$efengqi__qingguo1"] = "凌波微步，罗袜生尘。",
  ["$efengqi__qingguo2"] = "体迅飞凫，飘忽若神。",
  ["~efengqi__zhenji"] = "悼良会之永绝兮，哀一逝而异乡。",
}

local zhangliao = General(extension, "efengqi__zhangliao", "wei", 4)

local tuxi = fk.CreateTriggerSkill{
  name = "efengqi__tuxi",
  anim_type = "control",
  events = {fk.BeforeDrawCard},
  can_trigger = function(self, event, target, player, data)
    return data.who == player and player:hasSkill(self) and data.num > 0 and
      table.find(player.room:getOtherPlayers(player, false), function(p) return not p:isKongcheng() end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room:getOtherPlayers(player, false), function(p)
      return not p:isKongcheng() end), Util.IdMapper)
    local tos = room:askForChoosePlayers(player, targets, 1, data.num, "#efengqi__tuxi-choose:::"..data.num, self.name, true)
    if #tos > 0 then
      room:sortPlayersByAction(tos)
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = table.map(self.cost_data.tos, Util.Id2PlayerMapper)
    for _, to in ipairs(tos) do
      if not (to.dead or to:isKongcheng()) then
        local c = room:askForCardChosen(player, to, "h", self.name)
        room:obtainCard(player, c, false, fk.ReasonPrey)
        if player.dead then break end
      end
    end
    data.num = data.num - #tos
    if data.num == 0 and room:getBanner("@@efengqi__tuxi") ~= 1 then
      local turnEvent = room.logic:getCurrentEvent():findParent(GameEvent.Turn)
      if turnEvent then
        room:doIndicate(player.id, table.map(room.alive_players, Util.IdMapper))
        room:setBanner("@@efengqi__tuxi", 1)
        for _, p in ipairs(room.alive_players) do
          p:filterHandcards()
        end
        turnEvent:addCleaner(function()
          room:setBanner("@@efengqi__tuxi", 0)
          for _, p in ipairs(room.alive_players) do
            p:filterHandcards()
          end
        end)
      end
    end
  end,
}

local tuxi_filter = fk.CreateFilterSkill{
  name = "#efengqi__tuxi_filter",
  card_filter = function(self, card, player)
    return player and table.contains(player:getCardIds("h"), card.id) and card.trueName== "jink"
    and Fk:currentRoom():getBanner("@@efengqi__tuxi") == 1
  end,
  view_as = function(self, card)
    local c = Fk:cloneCard("thunder__slash", card.suit, card.number)
    c.skillName = "efengqi__tuxi"
    return c
  end,
}
tuxi:addRelatedSkill(tuxi_filter)

zhangliao:addSkill(tuxi)

Fk:loadTranslationTable{
  ["efengqi__zhangliao"] = "张辽",
  ["#efengqi__zhangliao"] = "",
  ["designer:efengqi__zhangliao"] = "屑",
  ["illustrator:efengqi__zhangliao"] = "鬼画府",

  ["efengqi__tuxi"] = "突袭",
  [":efengqi__tuxi"] = "当你摸牌时，可以少摸任意张，获得等量角色各一张手牌。若因此没有摸牌，本回合所有角色的【闪】视为雷【杀】。",
  ["#efengqi__tuxi-choose"] = "突袭：你可以少摸至多%arg张牌，获得等量其他角色各一张手牌",
  ["#efengqi__tuxi_filter"] = "突袭",
  ["@@efengqi__tuxi"] = "突袭:闪视为雷杀",

  ["$efengqi__tuxi1"] = "快马突袭，占尽先机！",
  ["$efengqi__tuxi2"] = "马似飞影，枪如霹雳！",
  ["~efengqi__zhangliao"] = "被敌人占了先机，呃。",
}

local xuchu = General(extension, "efengqi__xuchu", "wei", 4)
local luoyi = fk.CreateTriggerSkill{
  name = 'efengqi__luoyi',
  anim_type = "offensive",
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.n > 0
  end,
  on_use = function(self, event, target, player, data)
    data.n = data.n - 1
    player.room:addPlayerMark(player, "@@efengqi__luoyi", 1)
  end,

  refresh_events = {fk.EventPhaseStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and player.phase == Player.RoundStart
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@efengqi__luoyi", 0)
  end,
}
local luoyi_trigger = fk.CreateTriggerSkill{
  name = "#efengqi__luoyi_trigger",
  mute = true,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and not data.chain and data.card and
      ((player:getMark("@@efengqi__luoyi") > 0 and (data.card.trueName == "slash" or data.card.name == "duel")) or
      (player:hasSkill(luoyi) and #player:getCardIds("e") == 0 and data.card.name == "slash"))
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("efengqi__luoyi")
    room:notifySkillInvoked(player, "efengqi__luoyi")
    if player:getMark("@@efengqi__luoyi") > 0 and (data.card.trueName == "slash" or data.card.name == "duel") then
      data.damage = data.damage + 1
    end
    if player:hasSkill(luoyi) and #player:getCardIds("e") == 0 and data.card.name == "slash" then
      data.damage = data.damage + 1
    end
  end,
}
luoyi:addRelatedSkill(luoyi_trigger)
xuchu:addSkill(luoyi)
local nuzhan = fk.CreateTriggerSkill{
  name = "efengqi__jizhan",
  anim_type = "offensive",
  events = {fk.AfterSkillEffect},
  can_trigger = function(self, _, target, player, data)
    local slash = Fk:cloneCard 'slash'
    return player:hasSkill(self) and player.phase == Player.NotActive and
      target and target ~= player and
      player.room.logic:getCurrentEvent().n_caefengqi__jizhan and
      not player:prohibitUse(slash) and
      not player:isProhibited(target, slash)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, data, "#efengqi__jizhan-invoke::"..target.id)
  end,
  on_use = function(self, _, target, player, data)
    local room = player.room
    local slash = Fk:cloneCard 'slash'
    slash.skillName = self.name
    room:useCard {
      from = player.id,
      tos = { { target.id } },
      card = slash,
      additionalDamage = target:isWounded() and 0 or 1,
      disresponsiveList = table.map(room.alive_players, Util.IdMapper),
      extraUse = true,
    }
  end,

  refresh_events = {fk.AfterSkillEffect},
  can_refresh = function(self, _, target, player, data)
    return player:hasSkill(self) and player.phase == Player.NotActive and
      target and target ~= player and
      target:hasSkill(data) and data.visible and
      not player.room.logic:getCurrentEvent().efengqi__jizhan_counted
  end,
  on_refresh = function(self, _, target, _, _)
    local room = target.room
    local cur = room.logic:getCurrentEvent()
    cur.efengqi__jizhan_counted = true
    room:addPlayerMark(target, "@efengqi__jizhan-turn", 1)
    if (target:getMark("@efengqi__jizhan-turn") % 6 == 0) then
      cur.n_caefengqi__jizhan = true
    end
  end,
}
xuchu:addSkill(nuzhan)
Fk:loadTranslationTable{
  ["efengqi__xuchu"] = "许褚",
  ["designer:efengqi__xuchu"] = "notify",

  ["efengqi__luoyi"] = '裸衣',
  ["@@efengqi__luoyi"] = '裸衣',
  [':efengqi__luoyi'] = '摸牌阶段，你可以少摸一张牌，若如此做，直到你的下回合开始，' ..
    '你使用的【杀】或【决斗】造成的伤害+1；若你装备区里没有牌，你的普通【杀】' ..
    '造成的伤害+1。',
  ["#efengqi__luoyi_trigger"] = '裸衣',
  ["efengqi__jizhan"] = "急斩",
  ["@efengqi__jizhan-turn"] = "急斩",
  ["#efengqi__jizhan-invoke"] = "急斩: 现在你可以视为对 %dest 使用一张强中的【杀】，可能有加伤",
  [":efengqi__jizhan"] = "你的回合外，当其他角色于一回合内每发动六次技能后，" ..
    "你可以视为对其使用了一张不可响应的【杀】；若其未受伤，此【杀】伤害基数+1。" ..
    '<br /><font color="red">（注：由于判断发动技能的相关机制尚不完善，请不要汇报关于技能发动次数统计的bug）</font>',

  ["$efengqi__jizhan"] = "纳命来！",
  ["$efengqi__luoyi1"] = "过来打一架，对，就是你！",
  ["$efengqi__luoyi2"] = "废话少说，放马过来吧！",
  ["~efengqi__xuchu"] = "丞相，末将尽力了！",
}

local xiahoudun = General(extension, "efengqi__xiahoudun", "wei", 4)

local ganglie = fk.CreateTriggerSkill{
  name = "efengqi__ganglie",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
    return target.phase == Player.Finish and player:hasSkill(self)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = {}
    room.logic:getActualDamageEvents(1, function(e) table.insertIfNeed(targets, e.data[1].to) end)
    targets = table.filter(targets, function(p) return not p.dead and not p:isKongcheng() end)
    if #targets > 0 then
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 99999, "#efengqi__ganglie-choose", self.name, true)
      if #tos > 0 then
        room:sortPlayersByAction(tos)
        self.cost_data = {tos = tos}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = table.map(self.cost_data.tos, Util.Id2PlayerMapper)
    for _, to in ipairs(tos) do
      if not to:isKongcheng() then
        local cid = room:askForCardChosen(player, to, "h", self.name)
        room:throwCard(cid, self.name, to, player)
      end
      if player.dead then return end
    end
    if table.contains(tos, player) then
      tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#efengqi__ganglie-damage", self.name, false)
      if #tos > 0 then
        room:damage { from = player, to = room:getPlayerById(tos[1]), damage = 1, skillName = self.name }
      end
    else
      local judge = {
        who = player,
        reason = "floating_thunder",
        pattern = ".|.|spade",
      }
      room:judge(judge)
      if judge.card.suit == Card.Spade and not player.dead then
        room:damage{
          to = player,
          damage = 1,
          damageType = fk.ThunderDamage,
          skillName = self.name,
        }
      end
    end
  end,
}
xiahoudun:addSkill(ganglie)

local danqi = fk.CreateTriggerSkill{
  name = "efengqi__danqi",
  anim_type = "offensive",
  events = {fk.FinishJudge},
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card.color ~= Card.NoColor then
      return data.card.color == Card.Red or (#(player.room:getBanner("@$CenterArea") or {}) > 0
        or table.find(player.room.alive_players, function(p) return #p:getCardIds("ej") > 0
      end))
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if data.card.color == Card.Red then
      return true
    else
      if room:askForSkillInvoke(player, self.name, data, "#efengqi__danqi-invoke") then
        self.cost_data = {}
        local targets = table.filter(room.alive_players, function (p) return #p:getCardIds("ej") > 0 end)
        if #targets > 0 then
          local tos = room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1, "#efengqi__danqi-throw", self.name, true)
          if #tos > 0 then
            self.cost_data.tos = tos
          end
        end
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.card.color == Card.Red then
      room:damage { from = nil, to = player, damage = 1, skillName = self.name }
    else
      if self.cost_data.tos then
        local to = room:getPlayerById(self.cost_data.tos[1])
        if #to:getCardIds("ej") > 0 then
          local cid = room:askForCardChosen(player, to, "ej", self.name)
          room:throwCard(cid, self.name, to, player)
        end
      else
        local cards = room:getBanner("@$CenterArea") or {}
        if #cards > 0 then
          local card = room:askForCardChosen(player, player, { card_data = { { self.name, cards } } }, self.name, "$ChooseCard")
          room:obtainCard(player, card, true, fk.ReasonJustMove, player.id, self.name)
        end
      end
    end
  end,
}
danqi.CenterArea = true
xiahoudun:addSkill(danqi)

Fk:loadTranslationTable{
  ["efengqi__xiahoudun"] = "夏侯惇",
  ["#efengqi__xiahoudun"] = "",
  ["illustrator:efengqi__xiahoudun"] = "",
  ["designer:efengqi__xiahoudun"] = "老猫&楚萱",

  ["efengqi__ganglie"] = "刚烈",
  [":efengqi__ganglie"] = "一名角色的结束阶段，你可以弃置任意名本回合受到过伤害的角色各一张手牌，若含你，你对一名角色造成1点伤害，否则，你进行【浮雷】判定。",
  ["#efengqi__ganglie-choose"] = "刚烈：你可以弃置本回合受到过伤害的角色各一张手牌",
  ["#efengqi__ganglie-damage"] = "刚烈：请造成1点伤害",

  ["efengqi__danqi"] = "啖弃",
  [":efengqi__danqi"] = "当你的判定牌生效后，若结果为：红色，你受到1点伤害；黑色，你可以弃置场上一张牌或获得中央区一张牌。",
  --["#efengqi__danqi-damage"] = "啖弃：你可以受到1点无来源伤害！！！",
  ["#efengqi__danqi-invoke"] = "啖弃：你可以弃置场上一张牌或获得中央区一张牌",
  ["#efengqi__danqi-throw"] = "啖弃：你可以选择一名角色，弃置其场上一张牌。不选则改为你获得中央区一张牌",
}

local lidian = General(extension, "efengqi__lidian", "wei", 3)

local xunxun = fk.CreateTriggerSkill{
  name = "efengqi__xunxun",
  anim_type = "control",
  events = {fk.BeforeDrawCard},
  can_trigger = function(self, event, target, player, data)
    return target:getHandcardNum() == player:getHandcardNum() and player:hasSkill(self)
    and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(target, self.name, data, "#efengqi__xunxun-invoke:"..player.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:askForGuanxing(player, room:getNCards(4), nil, nil, self.name)
  end,
}
lidian:addSkill(xunxun)

local wangxi = fk.CreateTriggerSkill{
  name = "efengqi__wangxi",
  events = {fk.Damage, fk.Damaged},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from and data.from ~= data.to and not data.to.dead and not data.from.dead
    and not table.contains(player:getTableMark("efengqi__wangxi-turn"), event)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    room:addTableMark(player, "efengqi__wangxi-turn", event)
    local to = (event == fk.Damage and data.to or data.from)
    room:notifySkillInvoked(player, self.name, event == fk.Damaged and "masochism" or "drawcard", to and {to.id})
    player:drawCards(2, self.name)
    if not player.dead and not player:isNude() and to and not to.dead and to ~= player then
      local card = room:askForCard(player, 1, 1, true, self.name, false, ".", "#efengqi__wangxi-give:"..to.id)
      if #card > 0 then
        room:moveCardTo(card, Card.PlayerHand, to, fk.ReasonGive, self.name, nil, false, player.id)
      end
    end
  end,

  refresh_events = {fk.EnterDying},
  can_refresh = function (self, event, target, player, data)
    return target == player
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addTableMark(player, "efengqi__wangxi-turn", 0)
  end,
}
lidian:addSkill(wangxi)

Fk:loadTranslationTable{
  ["efengqi__lidian"] = "李典",
  ["#efengqi__lidian"] = "深明大义",
  ["illustrator:efengqi__lidian"] = "张帅",
  ["designer:efengqi__lidian"] = "屑",

  ["efengqi__xunxun"] = "恂恂",
  [":efengqi__xunxun"] = "每回合限一次，手牌数与你相同的角色摸牌时，其可以令你卜算4。",
  ["#efengqi__xunxun-invoke"] = "恂恂：你可以令 %src 卜算4张牌。",

  ["efengqi__wangxi"] = "忘隙",
  [":efengqi__wangxi"] = "每回合各限一次，当你对其他角色造成或受到其他角色造成的伤害后，可以摸两张牌并交给对方一张牌；当你进入濒死状态时，"..
  "此技能视为未发动。",
  ["#efengqi__wangxi-give"] = "忘隙：请交给 %src 一张牌。",

  ["$efengqi__xunxun1"] = "众将死战，非我之功。",
  ["$efengqi__xunxun2"] = "爱兵如子，胜乃可全。",
  ["$efengqi__wangxi1"] = "大丈夫，何拘小节。",
  ["$efengqi__wangxi2"] = "前尘往事，莫再提起。",
  ["~efengqi__lidian"] = "报国杀敌，虽死犹荣……",
}

local caozhang = General(extension, "efengqi__caozhang", "wei", 4)
Fk:loadTranslationTable{
  ["efengqi__caozhang"] = "曹彰",
  ["#efengqi__caozhang"] = "黄须儿",
  ["illustrator:efengqi__caozhang"] = "鬼画府",
  ["designer:efengqi__caozhang"] = "白驹",
  ["~efengqi__caozhang"] = "子桓，你害我！",
}

---@param player Player
local getJiangchiTimes = function (player)
  return 2 + player:getMark("efengqi__jiangchi-turn")
  - player:usedSkillTimes("efengqi__jiangchi", Player.HistoryPhase) - player:usedCardTimes("slash", Player.HistoryPhase)
end
local jiangchi = fk.CreateActiveSkill{
  name = "efengqi__jiangchi",
  anim_type = "drawcard",
  prompt = "#efengqi__jiangchi",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  times = function (self)
    if Self.phase == Player.NotActive then return -1 end
    return getJiangchiTimes(Self)
  end,
  can_use = function(self, player)
    return getJiangchiTimes(player) > 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:drawCards(1, self.name)
  end,
}
local jiangchi_targetmod = fk.CreateTargetModSkill{
  name = "#efengqi__jiangchi_targetmod",
  fix_times_func = function (self, player, skill, scope, card, to)
    if player:hasSkill(jiangchi) then
      return math.max(0, 2 + player:getMark("efengqi__jiangchi-turn") - player:usedSkillTimes(jiangchi.name, Player.HistoryPhase))
    end
  end,
}
local jiangchi_trigger = fk.CreateTriggerSkill{
  name = "#efengqi__jiangchi_trigger",
  mute = true,
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(jiangchi) and not target.dead and target ~= player and target.phase == Player.Play then
      return #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data[1]
        return use.from == target.id and use.card.trueName == "slash"
      end, Player.HistoryPhase) == 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(jiangchi.name)
    player.room:notifySkillInvoked(player, jiangchi.name, "special")
    player.room:addPlayerMark(player, "efengqi__jiangchi")
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("efengqi__jiangchi") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addPlayerMark(player, "efengqi__jiangchi-turn", player:getMark("efengqi__jiangchi"))
    player.room:setPlayerMark(player, "efengqi__jiangchi", 0)
  end,
}
jiangchi:addRelatedSkill(jiangchi_targetmod)
jiangchi:addRelatedSkill(jiangchi_trigger)
caozhang:addSkill(jiangchi)

Fk:loadTranslationTable{
  ["efengqi__jiangchi"] = "将驰",
  [":efengqi__jiangchi"] = "出牌阶段与你【杀】可使用次数共限两次，你可以摸一张牌。其他角色未使用【杀】的出牌阶段结束时，此技能下回合发动次数+1。",
  ["#efengqi__jiangchi"] = "将驰:摸一张牌，令【杀】可使用次数-1",

  ["$efengqi__jiangchi1"] = "谨遵父训，不可逞匹夫之勇。",
  ["$efengqi__jiangchi2"] = "吾定当身先士卒，振魏武雄风！",
}




local liubei = General(extension, "efengqi__liubei", "han", 4)

local juyi = fk.CreateViewAsSkill{
  name = "efengqi__juyi",
  prompt = "#efengqi__juyi-use",
  pattern = ".|.|.|.|.|basic",
  interaction = function(self)
    local all_names = Self:getTableMark("@$efengqi__juyi")
    local names = U.getViewAsCardNames(Self, self.name, all_names)
    if #names > 0 then
      return U.CardNameBox { choices = names }
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    if not self.interaction.data then return nil end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local mark = table.filter(player:getTableMark("@$efengqi__juyi"), function (name)
      return Fk:cloneCard(name).trueName ~= use.card.trueName
    end)
    room:setPlayerMark(player, "@$efengqi__juyi", #mark > 0 and mark or 0)
    room:askForYiji(player, player:getCardIds("he"), room:getOtherPlayers(player, false), self.name, 2, 999, "#efengqi__juyi-rende")
  end,
  enabled_at_play = function(self, player)
    return #player:getCardIds("he") > 1
    and table.find(Fk:currentRoom().alive_players, function (p) return p ~= player end)
  end,
  enabled_at_response = function(self, player, response)
    return not response and #player:getCardIds("he") > 1
    and table.find(Fk:currentRoom().alive_players, function (p) return p ~= player end)
  end,

  on_acquire = function (self, player)
    local room = player.room
    room:setPlayerMark(player, "@$efengqi__juyi", U.getAllCardNames("b"))
    for _, p in ipairs(room:getOtherPlayers(player, false)) do
      room:handleAddLoseSkills(p, "efengqi__juyi_other&", nil, false, true)
    end
  end,
  on_lose = function (self, player)
    local room = player.room
    room:setPlayerMark(player, "@$efengqi__juyi", 0)
    if table.find(room.alive_players, function (p)
      return p:hasSkill(self, true)
    end) then return end
    for _, p in ipairs(room.alive_players) do
      room:handleAddLoseSkills(p, "-efengqi__juyi_other&", nil, false, true)
    end
  end,
}

local efengqi__juyi_trigger = fk.CreateTriggerSkill{
  name = "#efengqi__juyi_trigger",

  refresh_events = {fk.RoundStart},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(juyi, true)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@$efengqi__juyi", U.getAllCardNames("b"))
  end,
}
juyi:addRelatedSkill(efengqi__juyi_trigger)

liubei:addSkill(juyi)

local efengqi__juyi_other = fk.CreateViewAsSkill{
  name = "efengqi__juyi_other&",
  prompt = "#efengqi__juyi-other",
  pattern = ".|.|.|.|.|basic",
  interaction = function(self)
    local all_names = {}
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if p ~= Self and p:hasSkill(juyi) then
        table.insertTableIfNeed(all_names, p:getTableMark("@$efengqi__juyi"))
      end
    end
    local names = U.getViewAsCardNames(Self, self.name, all_names)
    if #names > 0 then
      return U.CardNameBox { choices = names }
    end
  end,
  card_filter = function (self, to_select, selected)
    return #selected < 3 and (#selected == 0 or table.every(selected, function (id)
      return Fk:getCardById(id).color == Fk:getCardById(to_select).color
    end))
  end,
  view_as = function(self, cards)
    if not self.interaction.data or #cards ~= 3 then return nil end
    local card = Fk:cloneCard(self.interaction.data)
    card:setMark(self.name, cards)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local cards = use.card:getMark(self.name)
    if cards == 0 then return "" end
    local targets = table.filter(room.alive_players, function (p)
      return p ~= player and p:hasSkill(juyi, true) and table.find(p:getTableMark("@$efengqi__juyi"), function (name)
        return Fk:cloneCard(name).trueName == use.card.trueName
      end)
    end)
    if #targets == 0 then return "" end
    local to = #targets == 1 and targets[1] or room:getPlayerById(
      room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "", juyi.name, false)[1]
    )
    local mark = table.filter(to:getTableMark("@$efengqi__juyi"), function (name)
      return Fk:cloneCard(name).trueName ~= use.card.trueName
    end)
    room:setPlayerMark(to, "@$efengqi__juyi", #mark > 0 and mark or 0)
    room:obtainCard(to, cards, false, fk.ReasonGive, player.id, juyi.name)
  end,
  enabled_at_play = function(self, player)
    return #player:getCardIds("he") > 2
    and table.find(Fk:currentRoom().alive_players, function (p)
      return p ~= player and p:hasSkill(juyi) and p:getMark("@$efengqi__juyi") ~= 0
   end)
  end,
  enabled_at_response = function(self, player, response)
    return not response and Fk.currentResponsePattern and #player:getCardIds("he") > 2
    and table.find(Fk:currentRoom().alive_players, function (p)
      return p ~= player and p:hasSkill(juyi) and table.find(p:getTableMark("@$efengqi__juyi"), function (name)
        return Exppattern:Parse(Fk.currentResponsePattern):matchExp(name)
      end)
    end)
  end,
}
Fk:addSkill(efengqi__juyi_other)

local efengqi__shourong = fk.CreateTriggerSkill{
  name = "efengqi__shourong$",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player ~= target and target.phase == Player.Play and player:hasSkill(self) and not player.chained
  end,
  on_cost = function(self, event, target, player, data)
    self.cost_data = {tos = {target.id}}
    return player.room:askForSkillInvoke(player, self.name, nil, "#efengqi__shourong-invoke:"..target.id)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:setChainState(true)
    if target.dead then return end
    local ids = room:getCardsFromPileByRule(".|.|.|.|.|weapon")
    if #ids > 0 then
      room:obtainCard(target, ids, true, fk.ReasonJustMove, target.id, self.name)
      if target.dead then return end
    end
    if target.kingdom == "han" then
      ids = room:getCardsFromPileByRule(".|.|.|.|.|basic")
      if #ids > 0 then
        room:obtainCard(target, ids, true, fk.ReasonJustMove, target.id, self.name)
      end
    elseif target.kingdom == "shu" then
      room:recover { num = 1, skillName = self.name, who = target, recoverBy = player }
    end
  end,
}
liubei:addSkill(efengqi__shourong)

Fk:loadTranslationTable{
  ["efengqi__liubei"] = "刘备",
  ["#efengqi__liubei"] = "王道英风",
  ["illustrator:efengqi__liubei"] = "DH",
  ["designer:efengqi__liubei"] = "太师&永乐",

  ["efengqi__juyi"] = "聚义",
  [":efengqi__juyi"] = "每轮每种牌名限一次，你可以分配至少两张牌，视为使用一张基本牌；其他角色可以交给你三张同色牌视为使用一张基本牌。",
  ["#efengqi__juyi-use"] = "你可以分配至少两张牌，视为使用一张基本牌",
  ["efengqi__juyi_other&"] = "聚义",
  [":efengqi__juyi_other&"] = "每轮每种牌名限一次，你可以将三张同色牌交给有“聚义”的角色，视为使用一张基本牌",
  ["#efengqi__juyi-other"] = "选择你要视为使用的基本牌，将三张同色牌交给有“聚义”的角色",
  ["@$efengqi__juyi"] = "聚义",
  ["#efengqi__juyi-rende"] = "聚义：请分配至少两张牌",

  ["efengqi__shourong"] = "授戎",
  [":efengqi__shourong"] = "主公技，其他角色出牌阶段开始时，你可以横置，令其获得弃牌堆一张武器牌，若为汉势力角色，额外获得一张基本牌，若为蜀势力角色，回复1点体力。",
  ["#efengqi__shourong-invoke"] = "授戎：你可以横置，令 %src 获得弃牌堆一张武器牌(可能没有)，若其为汉、蜀角色额外获得收益",

  ["$efengqi__juyi1"] = "同心同德，救困扶危！",
  ["$efengqi__juyi2"] = "施仁布泽，乃我大汉立国之本！",
  ["$efengqi__shourong1"] = "哪位将军，替我拿下此贼！",
  ["$efengqi__shourong2"] = "欺我军无人乎！",
  ["~efengqi__liubei"] = "汉室未兴，祖宗未耀，朕实不忍此时西去……",
}

local guanyu = General(extension, "efengqi__guanyu", "han", 4)
local wusheng = fk.CreateViewAsSkill{
  name = "efengqi__wusheng",
  pattern = "slash",
  anim_type = "offensive",
  prompt = "#efengqi__wusheng",
  card_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, cards, player)
    local card = Fk:cloneCard("slash")
    if #cards == 1 then
      card:addSubcards(cards)
    elseif table.every(Fk:currentRoom().alive_players, function (p)
      return p:isNude() or p == player or table.contains(player:getTableMark("efengqi__wusheng-round"), p.id)
      end) then return nil
    end
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    use.extra_data = use.extra_data or {}
    if #use.card.subcards == 0 then
      local room = player.room
      local targets = table.filter(room:getOtherPlayers(player), function(p)
        return not table.contains(player:getTableMark("efengqi__wusheng-round"), p.id) and
        table.find(p:getCardIds("he"), function (id)
          local card = Fk:cloneCard("slash", Fk:getCardById(id).suit, Fk:getCardById(id).number)
          card.skillName = self.name
          if use.tos then
            return not player:prohibitUse(card)
          else
            return not player:prohibitResponse(card)
          end
        end) ~= nil
      end)
      if #targets == 0 then return self.name end
      local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#efengqi__wusheng-choose", self.name, false)
      to = room:getPlayerById(to[1])
      room:addTableMark(player, "efengqi__wusheng-round", to.id)
      local cards = table.filter(to:getCardIds("he"), function (id)
        local card = Fk:cloneCard("slash", Fk:getCardById(id).suit, Fk:getCardById(id).number)
        card.skillName = self.name
        if use.tos then
          return not player:prohibitUse(card)
        else
          return not player:prohibitResponse(card)
        end
      end)
      use.extra_data.efengqi__wusheng_to = to.id
      if #cards == 1 then
        use.card:addSubcard(cards[1])
      else
        local card_data = {}
        local data = {
          to = to.id,
          skillName = self.name,
          prompt = "#efengqi__wusheng-card::"..to.id,
        }
        local visible_data = {}
        local cards_data = table.filter(to:getCardIds("h"), function (id)
          return table.contains(cards, id)
        end)
        if #cards_data > 0 then
          table.insert(card_data, {"$Hand", cards_data})
          for _, id in ipairs(cards_data) do
            if not player:cardVisible(id) then
              visible_data[tostring(id)] = false
            end
          end
          if next(visible_data) == nil then visible_data = nil end
          data.visible_data = visible_data
        end
        cards_data = table.filter(to:getCardIds("e"), function (id)
          return table.contains(cards, id)
        end)
        if #cards_data > 0 then
          table.insert(card_data, {"$Equip", cards_data})
        end
        local ret = room:askForPoxi(player, self.name, card_data, data, false)
        use.card:addSubcards(ret)
      end
    end
  end,
  after_use = function (self, player, use)
    local room = player.room
    if player.dead or player:isNude() then return end
    if use.extra_data and use.extra_data.efengqi__wusheng_to then
      local to = room:getPlayerById(use.extra_data.efengqi__wusheng_to)
      if to.dead or to == player then return end
      local card = room:askForCard(player, 1, 1, true, self.name, true, ".|.|heart,diamond", "#efengqi__wusheng-give::"..to.id)
      if #card > 0 then
        room:moveCardTo(card, Card.PlayerHand, to, fk.ReasonGive, self.name, nil, false, player.id)
        if to:isWounded() and not to.dead then
          room:recover{
            who = to,
            num = 1,
            recoverBy = player,
            skillName = self.name,
          }
        end
      end
    end
  end,
  enabled_at_play = function(self, player)
    return table.find(Fk:currentRoom().alive_players, function (p)
      return not p:isNude() and not table.contains(player:getTableMark("efengqi__wusheng-round"), p.id)
    end)
  end,
  enabled_at_response = function (self, player, response)
    return table.find(Fk:currentRoom().alive_players, function (p)
      return not p:isNude() and not table.contains(player:getTableMark("efengqi__wusheng-round"), p.id)
    end)
  end,
}
Fk:addPoxiMethod{
  name = "efengqi__wusheng",
  prompt = function (data, extra_data)
    return extra_data.prompt
  end,
  card_filter = function (to_select, selected, data, extra_data)
    return #selected == 0
  end,
  feasible = function(selected, data)
    return #selected == 1
  end,
  default_choice = function(data)
    if not data then return {} end
    local cids = data[2][1]
    return cids
  end,
}
guanyu:addSkill(wusheng)
Fk:loadTranslationTable{
  ["efengqi__guanyu"] = "关羽",
  ["#efengqi__guanyu"] = "美髯公",
  ["illustrator:efengqi__guanyu"] = "凡果",
  ["designer:efengqi__guanyu"] = "胖即是胖",

  ["efengqi__wusheng"] = "武圣",
  [":efengqi__wusheng"] = "你可以将一名角色的一张牌（除你外每角色每轮限一次）当【杀】使用或打出，然后你可以交给其一张红色牌并令其回复1点体力。",
  ["#efengqi__wusheng"] = "武圣：将一名角色的一张牌当【杀】使用或打出<br>（先选择此【杀】的目标，然后选择你的牌或选择转化牌的角色）",
  ["#efengqi__wusheng-choose"] = "武圣：选择一名角色的一张牌用以转化",
  ["#efengqi__wusheng-card"] = "武圣：选择 %dest 的一张牌",
  ["#efengqi__wusheng-give"] = "武圣：是否交给 %dest 一张牌并令其回复1点体力？",

  ["$efengqi__wusheng1"] = "刀锋所向，战无不克！",
  ["$efengqi__wusheng2"] = "逆贼，哪里走！",
  ["~efengqi__guanyu"] = "桃园一拜，恩义常在……",
}

local zhangfei = General(extension, "efengqi__zhangfei", "han", 4)

local paoxiao = fk.CreateTriggerSkill{
  name = "efengqi__paoxiao",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:getMark("@@efengqi__paoxiao") > 0 and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@efengqi__paoxiao", 0)
    data.additionalDamage = (data.additionalDamage or 0) + 1
    if not data.extraUse then
      player:addCardUseHistory(data.card.trueName, -1)
      data.extraUse = true
    end
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@@efengqi__paoxiao", 0)
  end,
}
local paoxiao_delay = fk.CreateTriggerSkill{
  name = "#efengqi__paoxiao_delay",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(paoxiao)
  end,
  on_trigger = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@efengqi__paoxiao", data.card.type == Card.TypeBasic and 1 or 0)
  end,
}
local paoxiao_targetmod = fk.CreateTargetModSkill{
  name = "#efengqi__paoxiao_targetmod",
  bypass_times = function(self, player, skill, scope)
    return player:hasSkill(paoxiao) and skill.trueName == "slash_skill" and player:getMark("@@efengqi__paoxiao") > 0 and scope == Player.HistoryPhase
  end,
  bypass_distances = function(self, player, skill)
    return player:hasSkill(paoxiao) and skill.trueName == "slash_skill" and player:getMark("@@efengqi__paoxiao") > 0
  end,
}
paoxiao:addRelatedSkill(paoxiao_targetmod)
paoxiao:addRelatedSkill(paoxiao_delay)
zhangfei:addSkill(paoxiao)

local tishen = fk.CreateTriggerSkill{
  name = "efengqi__tishen",
  anim_type = "drawcard",
  frequency = Skill.Limited,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and player:isWounded() and
      player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#efengqi__tishen-invoke:::"..player:getLostHp())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = player:getLostHp()
    room:recover({
      who = player,
      num = n,
      recoverBy = player,
      skillName = self.name
    })
    if not player.dead then
      player:drawCards(n, self.name)
    end
  end,
}
zhangfei:addSkill(tishen)

Fk:loadTranslationTable{
  ["efengqi__zhangfei"] = "张飞",
  ["#efengqi__zhangfei"] = "",
  ["illustrator:efengqi__zhangfei"] = "",
  ["designer:efengqi__zhangfei"] = "",

  ["efengqi__paoxiao"] = "咆哮",
  [":efengqi__paoxiao"] = "锁定技，若你使用的上一张牌是基本牌，你使用【杀】无距离和次数限制且造成的伤害+1。",
  ["@@efengqi__paoxiao"] = "咆哮!",
  ["#efengqi__paoxiao_delay"] = "咆哮",

  ["efengqi__tishen"] = "替身",
  [":efengqi__tishen"] = "限定技，准备阶段，若你已受伤，则你可以将体力值回复至上限，然后摸回复数值张牌。",
  ["#efengqi__tishen-invoke"] = "替身: 你可以回复 %arg 点体力并摸 %arg 张牌",

  ["$efengqi__paoxiao1"] = "喝啊！",
  ["$efengqi__paoxiao2"] = "今，必斩汝马下！",
  ["$efengqi__tishen1"] = "欺我无谋，定要尔等血偿！",
  ["$efengqi__tishen2"] = "谁，还敢过来一战！？",
  ["~efengqi__zhangfei"] = "桃园一拜，此生…无憾……",
}

local zhugeliang = General(extension, "efengqi__zhugeliang", "han", 3)

local dawu = fk.CreateTriggerSkill{
  name = "efengqi__guanxing_dawu",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and data.damageType ~= fk.ThunderDamage
    and player:getMark("@@efengqi__guanxing_dawu-turn") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = Util.TrueFunc,

  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return player:getMark("@efengqi__guanxing_dawu") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local mark = {}
    for _, num in ipairs(player:getMark("@efengqi__guanxing_dawu")) do
      if num == 1 then
        player.room:setPlayerMark(player, "@@efengqi__guanxing_dawu-turn", 1)
      else
        table.insert(mark, num - 1)
      end
    end
    player.room:setPlayerMark(player, "@efengqi__guanxing_dawu", #mark > 0 and mark or 0)
  end,
}

local guanxing = fk.CreateTriggerSkill{
  name = "efengqi__guanxing",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local result = room:askForGuanxing(player, room:getNCards(5), nil, nil, self.name)
    local num = #result.bottom
    local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player, false), Util.IdMapper), 1, 1,
    "#efengqi__guanxing-choose:::"..num, self.name, true)
    if #tos > 0 then
      room.logic:addTriggerSkill(dawu)
      local to = room:getPlayerById(tos[1])
      if num == 0 then
        room:setPlayerMark(to, "@@efengqi__guanxing_dawu-turn", 1)
      else
        local mark = to:getTableMark("@efengqi__guanxing_dawu")
        if table.insertIfNeed(mark, num) then
          room:setPlayerMark(to, "@efengqi__guanxing_dawu", mark)
        end
      end
    end
  end,
}
zhugeliang:addSkill(guanxing)

local kongcheng = fk.CreateTriggerSkill{
  name = "efengqi__kongcheng",
  events = {fk.AskForCardUse, fk.AskForCardResponse, fk.FinishJudge},
  frequency = Skill.Compulsory,
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if event ~= fk.FinishJudge then
      if target == player and player:hasSkill(self) and not player:isFakeSkill(self) and
      (data.cardName == "jink" or (data.pattern and Exppattern:Parse(data.pattern):matchExp("jink"))) then
        local skill = Fk.skills["#eight_diagram_skill"]
        return skill and not player:hasSkill(skill, true) and skill:isEffectable(player)
      end
    else
      return player:isKongcheng() and target == player and player.room:getCardArea(data.card) == Card.Processing
      and data.reason == "eight_diagram" and data.extra_data and data.extra_data.efengqi__kongchengJudge
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.FinishJudge then
      local tos = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1,
      "#efengqi__kongcheng-give:::"..data.card:toLogString(), self.name, true)
      if #tos > 0 then
        self.cost_data = {tos = tos}
        return true
      end
    else
      self.cost_data = nil
      return player.room:askForSkillInvoke(player, "#eight_diagram_skill", data)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event ~= fk.FinishJudge then
      local judgeData = {
        who = player,
        reason = "eight_diagram",
        pattern = ".|.|heart,diamond",
        extra_data = {efengqi__kongchengJudge = true},
      }
      room:judge(judgeData)
      if judgeData.card.color == Card.Red then
        local card = Fk:cloneCard("jink")
        card.skillName = "eight_diagram"
        card.skillName = self.name
        if event == fk.AskForCardUse then
          if player:prohibitUse(card) then return false end
          data.result = {
            from = player.id,
            card = card,
          }
          if data.eventData then
            data.result.toCard = data.eventData.toCard
            data.result.responseToEvent = data.eventData.responseToEvent
          end
        else
          if player:prohibitResponse(card) then return false end
          data.result = card
        end
        return true
      end
    else
      room:obtainCard(room:getPlayerById(self.cost_data.tos[1]), data.card, true, fk.ReasonPrey, player.id, self.name)
    end
  end
}
zhugeliang:addSkill(kongcheng)

zhugeliang:addRelatedSkill(dawu)

Fk:loadTranslationTable{
  ["efengqi__zhugeliang"] = "诸葛亮",
  ["#efengqi__zhugeliang"] = "云霄一羽",
  ["illustrator:efengqi__zhugeliang"] = "官方",
  ["designer:efengqi__zhugeliang"] = "yyuaN",

  ["efengqi__guanxing"] = "观星",
  [":efengqi__guanxing"] = "准备阶段，你可以观看牌堆顶五张牌，将这些牌以任意顺序放回牌堆顶或牌堆底，然后可以令一名其他角色于此后第X个回合内获得“大雾”效果（X为置底牌数）",
  ["#efengqi__guanxing-choose"] = "观星：可以令一名其他角色于此后第 %arg 个回合内获得“大雾”",
  ["@@efengqi__guanxing_dawu-turn"] = "大雾:生效",
  ["@efengqi__guanxing_dawu"] = "大雾:",

  ["efengqi__kongcheng"] = "空城",
  [":efengqi__kongcheng"] = "你视为装备【八卦阵】，若你没有手牌，你可以令一名角色获得因此判定的判定牌。",
  ["#efengqi__kongcheng-give"] = "空城：你可以令一名角色获得判定牌%arg",

  ["efengqi__guanxing_dawu"] = "大雾",
  [":efengqi__guanxing_dawu"] = "若你有“大雾”标记，每当你受到不为雷电伤害的伤害时，防止此伤害。",

  ["$efengqi__guanxing1"] = "观今夜天象，知天下大事。",
  ["$efengqi__guanxing2"] = "知天易，逆天难。",
  ["$efengqi__kongcheng1"] = "（悠扬的琴音）",
  ["$efengqi__kongcheng2"] = "（低沉的琴音）",
  ["$efengqi__guanxing_dawu1"] = "此计可保你一时平安。",
  ["$efengqi__guanxing_dawu2"] = "此非万全之策，唯惧天雷。",
}

local machao = General(extension, "efengqi__machao", "han", 4)
local tieji = fk.CreateTriggerSkill{
  name = "efengqi__tieji",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.is_damage_card and #AimGroup:getAllTargets(data.tos) == 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".",
    }
    room:judge(judge)
    local to = room:getPlayerById(data.to)
    local suit = judge.card:getSuitString()
    if to.dead then return end
    local all_choices = {"efengqi__tieji2", "efengqi__tieji3"}
    if #room:askForDiscard(to, 1, 1, true, self.name, true, ".|.|"..judge.card:getSuitString(),
      "#efengqi__tieji-discard:::"..suit) > 0 then
      if not to.dead then
        local choice = room:askForChoice(to, all_choices, self.name)
        table.removeOne(all_choices, choice)
        if choice == "efengqi__tieji2" then
          room:setPlayerMark(to, "@@efengqi__tieji_basic-phase", 1)
        elseif choice == "efengqi__tieji3" then
          room:setPlayerMark(to, "@@efengqi__tieji_skill-turn", 1)
          room:addPlayerMark(to, MarkEnum.UncompulsoryInvalidity.."-turn", 1)
        end
      end
    else
      room:setPlayerMark(to, "@@efengqi__tieji_basic-phase", 1)
      room:setPlayerMark(to, "@@efengqi__tieji_skill-turn", 1)
      room:addPlayerMark(to, MarkEnum.UncompulsoryInvalidity.."-turn", 1)
    end
    if player.dead then return end
    if #all_choices == 1 then
      if room:askForSkillInvoke(player, self.name, nil, "#efengqi__tieji-draw") then
        if all_choices[1] == "efengqi__tieji2" then
          room:setPlayerMark(player, "@@efengqi__tieji_basic-phase", 1)
        elseif all_choices[1] == "efengqi__tieji3" then
          room:setPlayerMark(player, "@@efengqi__tieji_skill-turn", 1)
          room:addPlayerMark(player, MarkEnum.UncompulsoryInvalidity.."-turn", 1)
        end
        player:drawCards(2, self.name)
        room:askForDiscard(player, 1, 1, true, self.name, false)
      end
    elseif #room:askForDiscard(player, 1, 1, true, self.name, true, ".|.|"..judge.card:getSuitString(),
      "#efengqi__tieji-draw") > 0 then
      if player.dead then return end
      player:drawCards(2, self.name)
      room:askForDiscard(player, 1, 1, true, self.name, false)
    end
  end,
}
local tieji_prohibit = fk.CreateProhibitSkill{
  name = "#efengqi__tieji_prohibit",
  prohibit_use = function(self, player, card)
    return player:getMark("@@efengqi__tieji_basic-phase") > 0 and card.type == Card.TypeBasic
  end,
}
tieji:addRelatedSkill(tieji_prohibit)
machao:addSkill("mashu")
machao:addSkill(tieji)
Fk:loadTranslationTable{
  ["efengqi__machao"] = "马超",
  ["#efengqi__machao"] = "一骑当千",
  ["illustrator:efengqi__machao"] = "刘小狼",
  ["designer:efengqi__machao"] = "屑",

  ["efengqi__tieji"] = "铁骑",
  [":efengqi__tieji"] = "当你使用伤害牌指定唯一目标后，你可以进行一次判定，其执行两项：1.弃置一张同花色牌；2.本阶段无法使用基本牌；"..
  "3.本回合非锁定技失效。然后你可以执行剩余项，摸两张牌再弃置一张牌。",
  ["#efengqi__tieji-discard"] = "铁骑：弃置一张%arg牌，否则本回合无法使用基本牌且非锁定技失效！",
  ["efengqi__tieji2"] = "本阶段无法使用基本牌",
  ["efengqi__tieji3"] = "本回合非锁定技失效",
  ["@@efengqi__tieji_basic-phase"] = "禁止使用基本牌",
  ["@@efengqi__tieji_skill-turn"] = "非锁定技失效",
  ["#efengqi__tieji-draw"] = "铁骑：是否执行剩余项，摸2张牌再弃1张牌？",

  ["$efengqi__tieji1"] = "目标敌阵，全军突击！",
  ["$efengqi__tieji2"] = "敌人阵型已乱，随我杀！",
  ["~efengqi__machao"] = "请将我，葬在西凉……",
}

local huangyueying = General(extension, "efengqi__huangyueying", "han", 3, 3, General.Female)

local jizhi = fk.CreateTriggerSkill{
  name = "efengqi__jizhi",
  events = {fk.CardUsing},
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player == target and data.card.type == Card.TypeTrick
    --and table.find(player.room.alive_players, function (p)
    --  return not table.contains(player:getTableMark("efengqi__jizhi-turn"), p.id)
    --end)
  end,
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(player.room.alive_players, function (p)
      return not table.contains(player:getTableMark("efengqi__jizhi-turn"), p.id)
    end)
    local tos = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#efengqi__jizhi-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    to:drawCards(1, self.name)
    if to ~= player and not player.dead and not to:isNude() then
      local cards = room:askForCard(to, 1, 1, true, self.name, true, ".", "#efengqi__jizhi-give:"..player.id)
      if #cards > 0 then
        room:addTableMark(player, "efengqi__jizhi-turn", to.id)
        room:obtainCard(player, cards, false, fk.ReasonGive, to.id, self.name)
      end
    end
  end,
}
huangyueying:addSkill(jizhi)

local cangji = fk.CreateTriggerSkill{
  name = "efengqi__cangji",
  anim_type = "drawcard",
  events = {fk.GameStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return  player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = {}
    for _, name in ipairs({"ex_nihilo", "eight_diagram"}) do
      local ret = room:getCardsFromPileByRule(name)[1]
      if not ret then
        local suit, num = Card.Spade, 1
        for cardName, card in pairs(Fk.all_card_types) do
          if cardName == name then
            suit = card.suit
            num = card.number
            break
          end
        end
        ret = room:printCard(name, suit, num).id
        room:setCardMark(Fk:getCardById(ret), MarkEnum.DestructIntoDiscard, 1)
      end
      table.insert(ids, ret)
    end
    room:obtainCard(player, ids, true, fk.ReasonJustMove, player.id, self.name)
  end,

  refresh_events = {fk.DrawInitialCards},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self) and target == player
  end,
  on_refresh = function (self, event, target, player, data)
    data.num = math.max(data.num - 2, 0)
  end,
}
huangyueying:addSkill(cangji)

Fk:loadTranslationTable{
  ["efengqi__huangyueying"] = "黄月英",
  ["#efengqi__huangyueying"] = "",
  ["illustrator:efengqi__huangyueying"] = "光域",
  ["designer:efengqi__huangyueying"] = "zzcclll朱苦力",

  ["efengqi__jizhi"] = "集智",
  [":efengqi__jizhi"] = "你使用锦囊牌时，你可以令一名角色摸一张牌，若不为你，其可以交给你一张牌，令你本回合不能以此法选择该角色。",
  ["#efengqi__jizhi-choose"] = "集智：你可以令一名角色摸一张牌，其可以交给你一张牌",
  ["#efengqi__jizhi-give"] = "集智：你可以交给 %src 一张牌",

  ["efengqi__cangji"] = "藏机",
  [":efengqi__cangji"] = "锁定技，你的初始手牌-2；游戏开始时，你获得一张【八卦阵】与【无中生有】。",

  ["$efengqi__jizhi1"] = "得上通，智集心。",
  ["$efengqi__jizhi2"] = "集万千才智，致巧趣鲜用。",
  ["$efengqi__cangji1"] = "哼哼～",
  ["$efengqi__cangji2"] = "哼～",
  ["~efengqi__huangyueying"] = "亮……",
}

local zhaoyun = General(extension, "efengqi__zhaoyun", "han", 4)

local qizhen = fk.CreateViewAsSkill{
  name = "efengqi__qizhen",
  anim_type = "offensive",
  pattern = ".|.|.|.|.|basic",
  prompt = "#efengqi__qizhen",
  interaction = function(self)
    local all_choices = U.getAllCardNames("b")
    local choices = U.getViewAsCardNames(Self, self.name, all_choices)
    if #choices > 0 then
      return U.CardNameBox { choices = choices, all_choices = all_choices }
    end
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeBasic and self.interaction.data
    and Fk:cloneCard(self.interaction.data).trueName ~= Fk:getCardById(to_select).trueName
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return nil end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = self.name
    c:addSubcard(cards[1])
    c:setMark("efengqi__qizhen_from", Self.id) -- extra_data无法附加在打出的事件上
    return c
  end,
  enabled_at_play = function(self, player)
    return true
  end,
  enabled_at_response = function (self, player, response)
    return not player:isKongcheng()
  end,
}

local qizhen_trigger = fk.CreateTriggerSkill{
  name = "#efengqi__qizhen_trigger",
  events = {fk.CardUseFinished, fk.CardRespondFinished},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(qizhen) and not player.room.current.dead
    and player:getHandcardNum() ~= player.room.current:getHandcardNum()
    and data.card:getMark("efengqi__qizhen_from") == player.id
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local name1, name2 = data.card.trueName, nil
    if #data.card.subcards > 0 then
      name2 = Fk:getCardById(data.card.subcards[1]).trueName
    end
    local current = room.current
    local all_choices = table.filter(U.getAllCardNames("b"), function (name)
      return Fk:cloneCard(name).trueName ~= name1 and Fk:cloneCard(name).trueName ~= name2
    end)
    local choices = table.filter(all_choices, function (name)
      local card = Fk:cloneCard(name)
      card.skillName = qizhen.name
      return player:canUseTo(card, current, {bypass_distances = true, bypass_times = true, fix_targets = {current.id}})
    end)
    if #choices == 0 then return end
    choices = U.askForChooseCardNames(room, player, choices, 1, 1, qizhen.name,
    "#efengqi__qizhen-card::"..current.id..":"..current:getHandcardNum(), all_choices, true)
    if #choices > 0 then
      local num = player:getHandcardNum() - current:getHandcardNum()
      if num > 0 then
        room:askForDiscard(player, num, num, false, qizhen.name, false)
      elseif num < 0 then
        player:drawCards(-num, qizhen.name)
      end
      room:useVirtualCard(choices[1], nil, player, current, qizhen.name, true)
    end
  end,
}
qizhen:addRelatedSkill(qizhen_trigger)

zhaoyun:addSkill(qizhen)

Fk:loadTranslationTable{
  ["efengqi__zhaoyun"] = "赵云",
  ["#efengqi__zhaoyun"] = "虎威将军",
  ["illustrator:efengqi__zhaoyun"] = "",
  ["designer:efengqi__zhaoyun"] = "Romantic",

  ["efengqi__qizhen"] = "旂阵",
  [":efengqi__qizhen"] = "你可以将一张基本牌当另一张基本牌使用或打出，然后可以将手牌调整至与当前回合角色相同并视为对其使用第三种基本牌。",
  ["#efengqi__qizhen"] = "旂阵：可以将一张基本牌当另一张基本牌使用或打出",
  ["#efengqi__qizhen_trigger"] = "旂阵",
  ["#efengqi__qizhen-card"] = "旂阵：你可以将手牌调整至 %arg 张，并视为对 %dest 使用第三种基本牌",
  ["@$efengqi__qizhen-turn"] = "旂阵",

  ["$efengqi__qizhen1"] = "为将者，自当尽忠尽职。",
  ["$efengqi__qizhen2"] = "一人一枪一匹马，疆场尽驰骋。",
  ["~efengqi__zhaoyun"] = "你们谁…还敢再上……",
}

local yijik = General(extension, "efengqi__yijik", "han", 3)
local jiyuan = fk.CreateViewAsSkill{
  name = "efengqi__jiyuan",
  anim_type = "support",
  pattern = ".|.|.|.|.|basic",
  prompt = "#efengqi__jiyuan",
  interaction = function(self, player)
    local all_names = U.getAllCardNames("b")
    local names = U.getViewAsCardNames(player, self.name, all_names)
    if #names > 0 then
      return U.CardNameBox { choices = names, all_choices = all_names }
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    if not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    room:broadcastPlaySound("./packages/standard_cards/audio/card/"..(player.gender == General.Male and "male" or "female")..
      "/"..use.card.name)
    room:broadcastPlaySound("./packages/maneuvering/audio/card/"..(player.gender == General.Male and "male" or "female")..
      "/"..use.card.name)
    if use.tos then
      room:doIndicate(player.id, TargetGroup:getRealTargets(use.tos))
    end
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
      "#efengqi__jiyuan-choose", self.name, false)
    to = room:getPlayerById(to[1])
    to:drawCards(1, self.name)
    local cardResponded
    if not to.dead then
      cardResponded = room:askForResponse(to, self.name, ".|.|.|.|"..use.card.name,
      "#efengqi__jiyuan-ask:"..player.id.."::"..use.card.name, true)
    end
    if cardResponded then
      room:responseCard({
        from = to.id,
        card = cardResponded,
        skipDrop = true,
      })
      use.card = cardResponded
    else
      if player == room.current then
        room:invalidateSkill(player, self.name, "-turn")
      end
      return self.name
    end
  end,
  enabled_at_play = function (self, player)
    return true
  end,
  enabled_at_response = function(self, player, response)
    return not response
  end,
}
--[[
local jiyuan_prohibit = fk.CreateProhibitSkill{
  name = "#efengqi__jiyuan_prohibit",
  prohibit_use = function(self, player, card)
    return table.contains(player:getTableMark("efengqi__jiyuan-phase"), card.name)
  end,
}
jiyuan:addRelatedSkill(jiyuan_prohibit)
--]]
yijik:addSkill(jiyuan)
Fk:loadTranslationTable{
  ["efengqi__yijik"] = "伊籍",
  ["#efengqi__yijik"] = "",
  ["illustrator:efengqi__yijik"] = "凝聚永恒",
  ["designer:efengqi__yijik"] = "屑&柠檬",
  --[[
  ["efengqi__jijie"] = "机捷",
  [":efengqi__jijie"] = "牌堆底的牌对你可见。你摸牌时，或后，可以将之置于牌堆顶。",--省事了
  --]]
  ["efengqi__jiyuan"] = "急援",
  [":efengqi__jiyuan"] = "当你需要使用基本牌时，可以令一名角色摸一张牌，其可代替你使用之。若为你回合内且其未使用，则“急援”本回合失效。",
  ["#efengqi__jiyuan"] = "急援：声明你要使用的基本牌和目标，令一名角色摸一张牌，请求其替你使用此牌",
  ["#efengqi__jiyuan-choose"] = "急援：令一名角色摸一张牌，其替你使用此牌或你本阶段不能使用此牌",
  ["#efengqi__jiyuan-ask"] = "急援：是否替 %src 使用一张【%arg】？",

  ["$efengqi__jijie1"] = "一拜一起，未足为劳。",
  ["$efengqi__jijie2"] = "识言观行，方能雍容风议。",
  ["$efengqi__jiyuan1"] = "公若辞，必遭蔡瑁之害矣。",
  ["$efengqi__jiyuan2"] = "形势危急，还请速行。",
  ["~efengqi__yijik"] = "未能，救得刘公脱险……",
}

local lvbu = General(extension, "efengqi__lvbu", "han", 4)

local wushuang = fk.CreateTriggerSkill{
  name = "efengqi__wushuang",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or target ~= player or data.card.trueName ~= "slash" then return false end
    if event == fk.CardUsing then
      return true
    else
      return table.find(Card:getIdList(data.card), function (id)
        return player.room:getCardArea(id) == Card.Processing
      end)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      local num = 2
      local orig = TargetGroup:getRealTargets(data.tos)
      local targets = table.filter(room.alive_players, function (p)
        return not table.contains(orig, p.id) and not player:isProhibited(p, data.card)
        and data.card.skill:modTargetFilter(p.id, {}, player, data.card, true)
      end)
      if #targets > 0 then
        local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, num,
        "#efengqi__wushuang-choose:::"..data.card:toLogString(), self.name, true)
        if #tos > 0 then
          for _, pid in ipairs(tos) do
            table.insert(data.tos, {pid})
          end
          num = num - #tos
        end
      end
      if num > 0 then
        data.extra_data = data.extra_data or {}
        data.extra_data.efengqi__wushuangNum = num
      end
    else
      local cards = table.filter(Card:getIdList(data.card), function (id)
        return room:getCardArea(id) == Card.Processing
      end)
      room:obtainCard(player, cards, true, fk.ReasonJustMove, player.id, self.name)
    end
  end,

  refresh_events = {fk.TargetSpecified},
  can_refresh = function (self, event, target, player, data)
    return target == player and data.extra_data and data.extra_data.efengqi__wushuangNum
  end,
  on_refresh = function (self, event, target, player, data)
    data.fixedResponseTimes = data.fixedResponseTimes or {}
    data.fixedResponseTimes["jink"] = (data.fixedResponseTimes["jink"] or 1) + data.extra_data.efengqi__wushuangNum
  end,
}
lvbu:addSkill(wushuang)
local liyu = fk.CreateTriggerSkill{
  name = "efengqi__liyu",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash"
    and data.to ~= player and not data.to.dead and not data.to:isAllNude()
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, data, "#efengqi__liyu-invoke::" .. data.to.id) then
      self.cost_data = {tos = {data.to.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.to
    local id = room:askForCardChosen(player, to, "hej", self.name)
    room:obtainCard(player, id, true, fk.ReasonPrey, player.id, self.name)
    if Fk:getCardById(id).type ~= Card.TypeEquip then
      if not to.dead then
        to:drawCards(1, self.name)
      end
    else
      local card = Fk:cloneCard("duel")
      if player:prohibitUse(card) then return false end
      local targets = table.filter(room.alive_players, function(p)
        return not player:isProhibited(p, card) and p ~= player and p ~= to
      end)
      if #targets == 0 then return false end
      local victim = room:askForChoosePlayers(to, table.map(targets, Util.IdMapper), 1, 1,
        "#efengqi__liyu-ask:" .. player.id, self.name, false)[1]
      room:useVirtualCard("duel", nil, player, room:getPlayerById(victim), self.name)
    end
  end,
}
lvbu:addSkill(liyu)
--[[
local jiwu = fk.CreateTriggerSkill{
  name = "efengqi__jiwu",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.TargetSpecified then
        return data.card.trueName == "slash"
      elseif event == fk.Damage then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      data.fixedResponseTimes = data.fixedResponseTimes or {}
      data.fixedResponseTimes["jink"] = 1 + player:getMark("@efengqi__jiwu")[1]
    elseif event == fk.Damage then
      local room = player.room
      local all_choices, result = {"1", "2", "3"}, {}
      local n1 = room:askForChoice(player, all_choices, self.name, "#efengqi__jiwu1-ask")
      table.removeOne(all_choices, n1)
      n1 = tonumber(n1)
      table.insert(result, n1)
      local n2 = room:askForChoice(player, all_choices, self.name, "#efengqi__jiwu2-ask")
      table.removeOne(all_choices, n2)
      n2 = tonumber(n2)
      table.insert(result, n2)
      table.insert(result, tonumber(all_choices[1]))
      room:setPlayerMark(player, "@efengqi__jiwu", result)
    end
  end,

  on_acquire = function (self, player, is_start)
    player.room:setPlayerMark(player, "@efengqi__jiwu", {1, 2, 3})
  end,
  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@efengqi__jiwu", 0)
  end,
}
local jiwu_targetmod = fk.CreateTargetModSkill{
  name = "#efengqi__jiwu_targetmod",
  frequency = Skill.Compulsory,
  extra_target_func = function(self, player, skill)
    if skill.trueName == "slash_skill" and player:hasSkill(jiwu) then
      return player:getMark("@efengqi__jiwu")[2]
    end
  end,
}
local jiwu_attackrange = fk.CreateAttackRangeSkill{
  name = "#efengqi__jiwu_attackrange",
  frequency = Skill.Compulsory,
  correct_func = function (self, from, to)
    if from:hasSkill(jiwu) then
      return from:getMark("@efengqi__jiwu")[3]
    end
    return 0
  end,
}
jiwu:addRelatedSkill(jiwu_targetmod)
jiwu:addRelatedSkill(jiwu_attackrange)
lvbu:addSkill(jiwu)
--]]
Fk:loadTranslationTable{
  ["efengqi__lvbu"] = "吕布",
  ["#efengqi__lvbu"] = "武开穹巅",
  ["designer:efengqi__lvbu"] = "白驹",
  ["illustrator:efengqi__lvbu"] = "鱼仔",

  ["efengqi__wushuang"] = "无双",
  [":efengqi__wushuang"] = "锁定技，当你使用【杀】时，需增加至多两个目标，每少增加一个，响应所需【闪】+1。你打出【杀】时获得之。",
  ["#efengqi__wushuang-choose"] = "无双：为你使用的%arg增加至多两个目标",

--[[
  ["efengqi__jiwu"] = "极武",
  [":efengqi__jiwu"] = "锁定技，你使用【杀】的：响应量+1、可指定目标数+2；攻击范围+3；你造成伤害后，可以重新分配数字！",
  ["@efengqi__jiwu"] = "极武",
  ["#efengqi__jiwu1-ask"] = "极武：选择你使用【杀】所需响应数+",
  ["#efengqi__jiwu2-ask"] = "极武：选择你使用【杀】额外指定目标数+",
  --]]

  ["efengqi__liyu"] = "利驭",
  [":efengqi__liyu"] = "当你使用【杀】对一名其他角色造成伤害后，你可获得其区域里的一张牌。然后若获得的牌不是装备牌，其摸一张牌；若获得的牌是装备牌，则视为你对由其指定的另一名其他角色使用一张【决斗】。",
  ["#efengqi__liyu-invoke"] = "利驭：你可获得 %dest 区域里的一张牌",
  ["#efengqi__liyu-ask"] = "利驭：选择一名角色，视为 %src 对其使用【决斗】",

  ["$efengqi__wushuang1"] = "别再做无谓的挣扎了！",
  ["$efengqi__wushuang2"] = "无敌还真是寂寞啊。",
  ["$efengqi__jiwu1"] = "还有哪个敢挑战我！？",
  ["$efengqi__jiwu2"] = "三个齐上，也不是我的对手！",
  ["$efengqi__liyu1"] = "人不为己，天诛地灭。",
  ["$efengqi__liyu2"] = "大丈夫，相时而动。",
  ["~efengqi__lvbu"] = "我竟然输了……不可能！",
}

local sunquan = General(extension, "efengqi__sunquan", "wu", 4)

local zhiheng = fk.CreateActiveSkill{
  name = "efengqi__zhiheng",
  anim_type = "drawcard",
  card_num = 0,
  target_num = 1,
  interaction = function(self)
    local all_choices = {"efengqi__zhiheng1", "efengqi__zhiheng2"}
    local choices = table.filter(all_choices, function (ch)
      return Self:getMark(ch.."-phase") == 0
    end)
    if #choices > 0 then
      return UI.ComboBox { choices = choices, all_choices = all_choices }
    end
  end,
  prompt = "#efengqi__zhiheng",
  can_use = function(self, player)
    return player:getMark("efengqi__zhiheng1-phase") == 0 or player:getMark("efengqi__zhiheng2-phase") == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected)
    local to = Fk:currentRoom():getPlayerById(to_select)
    if self.interaction.data == "efengqi__zhiheng1" then
      return to:getHandcardNum() % 2 == 1
    else
      return to:getHandcardNum() % 2 == 0
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local choice = self.interaction.data
    room:setPlayerMark(player, choice.."-phase", 1)
    local num = 3
    if choice:endsWith("1") then
      to:drawCards(num, self.name)
      if not to.dead and not to:isKongcheng() then
        num = to:getHandcardNum() // 2
        room:askForDiscard(to, num, num, false, self.name, false)
      end
    else
      num = to:getHandcardNum() // 2
      room:askForDiscard(to, num, num, false, self.name, false)
      if not to.dead then
        to:drawCards(3, self.name)
      end
    end
  end,
}
sunquan:addSkill(zhiheng)

local jiuyuan = fk.CreateTriggerSkill{
  name = "efengqi__jiuyuan$",
  anim_type = "drawcard",
  events = {fk.TargetConfirmed},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card.trueName == "peach" and target == player and data.from ~= player.id
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)
    local from = room:getPlayerById(data.from)
    if from.kingdom == "wu" then
      data.additionalEffect = (data.additionalEffect or 0) + 1
    end
  end
}
sunquan:addSkill(jiuyuan)

Fk:loadTranslationTable{
  ["efengqi__sunquan"] = "孙权",
  ["#efengqi__sunquan"] = "轻冠镇江",
  ["designer:efengqi__sunquan"] = "廷玉",
  ["illustrator:efengqi__sunquan"] = "蛋蛋",

  ["efengqi__zhiheng"] = "制衡",
  [":efengqi__zhiheng"] = "出牌阶段各限一次，你可以：令一名手牌数为奇数的角色摸三张牌并弃置半数手牌；令一名手牌数为偶数的角色弃置半数手牌并摸三张牌。",
  ["#efengqi__zhiheng"] = "制衡：令一名角色摸三弃半，或弃半摸三！",
  ["efengqi__zhiheng1"] = "令奇数手牌数角色摸三弃半",
  ["efengqi__zhiheng2"] = "令偶数手牌数角色弃半摸三",

  ["efengqi__jiuyuan"] = "救援",
  [":efengqi__jiuyuan"] = "主公技，锁定技，其他角色对你使用【桃】时，你摸一张牌，若为吴势力角色，令之多结算一次。",

  ["$efengqi__zhiheng1"] = "不急不躁，稳谋应对。",
  ["$efengqi__zhiheng2"] = "制衡互牵，大局可安。",
  ["$efengqi__jiuyuan1"] = "你们真是朕的得力干将。",
  ["$efengqi__jiuyuan2"] = "有爱卿在，朕无烦忧。",
  ["~efengqi__sunquan"] = "锦绣江东，岂能失于我手……",
}


local ganning = General(extension, "efengqi__ganning", "wu", 4)

local qixi = fk.CreateViewAsSkill{
  name = "efengqi__qixi",
  anim_type = "control",
  pattern = "dismantlement",
  prompt = "#efengqi__qixi",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local c = Fk:cloneCard("dismantlement")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end
}

local qixi_delay = fk.CreateTriggerSkill{
  name = "#efengqi__qixi_delay",
  mute = true,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(qixi) and not player:isNude()
    and table.contains(data.card.skillNames, qixi.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local useEvent = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
    if not useEvent then return end
    local ids = {}
    useEvent:searchEvents(GameEvent.MoveCards, 1, function (e)
      if e.parent and e.parent.parent and e.parent.parent.event == GameEvent.CardEffect
      and e.parent.parent.data[1].card == data.card then
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard and move.skillName:endsWith("dismantlement_skill") then
            for _, info in ipairs(move.moveInfo) do
              if room:getCardArea(info.cardId) == Card.DiscardPile then
                table.insertIfNeed(ids, info.cardId)
              end
            end
          end
        end
      end
    end)
    if #ids > 0 then
      local tos, cardId = room:askForChooseCardAndPlayers(player, table.map(room:getOtherPlayers(player, false), Util.IdMapper),
      1, 1, ".|.|diamond,heart", "#efengqi__qixi-red:::"..#ids, qixi.name, true)
      if #tos == 0 then return end
      room:obtainCard(room:getPlayerById(tos[1]), cardId, true, fk.ReasonGive, player.id, qixi.name)
      if player.dead then return end
      ids = table.filter(ids, function (id) return room:getCardArea(id) == Card.DiscardPile end)
      room:askForYiji(player, ids, nil, qixi.name, #ids, #ids, nil, ids)
    end
  end,
}
qixi:addRelatedSkill(qixi_delay)

ganning:addSkill(qixi)

local fenwei = fk.CreateTriggerSkill{
  name = "efengqi__fenwei",
  anim_type = "defensive",
  frequency = Skill.Limited,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card.type == Card.TypeTrick and #AimGroup:getAllTargets(data.tos) > 1 and data.firstTarget
    and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local tos = player.room:askForChoosePlayers(player, AimGroup:getAllTargets(data.tos),
      1, 999, "#efengqi__fenwei-choose:::"..data.card:toLogString(), self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    table.insertTableIfNeed(data.nullifiedTargets, self.cost_data.tos)
  end,
}
ganning:addSkill(fenwei)

Fk:loadTranslationTable{
  ["efengqi__ganning"] = "甘宁",
  ["#efengqi__ganning"] = "锦帆游侠",
  ["designer:efengqi__ganning"] = "隐匿",
  ["illustrator:efengqi__ganning"] = "太玄工作室",

  ["efengqi__qixi"] = "奇袭",
  [":efengqi__qixi"] = "你可以将黑色牌当【过河拆桥】使用，然后你可以交出一张红色牌，分配弃置牌。",
  ["#efengqi__qixi"] = "奇袭：将黑色牌当【过河拆桥】使用，然后可交出一张红色牌，分配弃置牌",
  ["#efengqi__qixi-red"] = "奇袭：你可以交出一张红色牌，分配 %arg 张弃置牌",
  ["#efengqi__qixi_delay"] = "奇袭",

  ["efengqi__fenwei"] = "奋威",
  [":efengqi__fenwei"] = "限定技，当一张锦囊牌指定多个目标后，你可令此牌对其中任意个目标无效。",
  ["#efengqi__fenwei-choose"] = "奋威：你可以令此%arg对任意个目标无效",

  ["$efengqi__qixi1"] = "弟兄们，准备动手！",
  ["$efengqi__qixi2"] = "你用不了这么多了！",
  ["$efengqi__fenwei1"] = "奋勇当先，威名远扬！",
  ["$efengqi__fenwei2"] = "哼！敢欺我东吴无人。",
  ["~efengqi__ganning"] = "别管我，继续上！",
}


local lvmeng = General(extension, "efengqi__lvmeng", "wu", 4)
local keji = fk.CreateTriggerSkill{
  name = "efengqi__keji",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.from == player.id and move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).trueName == "slash" then
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local ids = {}
    for _, move in ipairs(data) do
      if move.from == player.id and move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard then
        for _, info in ipairs(move.moveInfo) do
          table.insert(ids, info.cardId)
        end
      end
    end
    local n = #ids
    if table.every(ids, function (id)
      return Fk:getCardById(id).trueName == "slash"
    end) then
      n = 2 * n
    end
    player:drawCards(n, self.name)
  end,
}
lvmeng:addSkill(keji)
Fk:loadTranslationTable{
  ["efengqi__lvmeng"] = "吕蒙",
  ["#efengqi__lvmeng"] = "白衣渡江",
  ["designer:efengqi__lvmeng"] = "食马者",
  ["illustrator:efengqi__lvmeng"] = "M云涯",

  ["efengqi__keji"] = "克己",
  [":efengqi__keji"] = "你弃置牌后，若包含【杀】，摸等量牌；若均为【杀】，改为摸两倍的牌。",

  ["$efengqi__keji1"] = "蓄力待时，不争首功。",
  ["$efengqi__keji2"] = "最好的机会，还在等着我。",
  ["~efengqi__lvmeng"] = "你，给我等着！",
}


local huanggai = General(extension, "efengqi__huanggai", "wu", 4)

local zhaxiang = fk.CreateActiveSkill{
  name = "efengqi__zhaxiang",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "#efengqi__zhaxiang",
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    to:drawCards(1, self.name)
    if to.dead or player.dead or to:isKongcheng() then return end
    local use = room:useVirtualCard("fire_attack", nil, player, to, self.name)
    if use and use.damageDealt and use.damageDealt[player.id] then
      player:setSkillUseHistory(self.name, 0, Player.HistoryPhase)
    end
  end,
}
huanggai:addSkill(zhaxiang)

local kurou = fk.CreateTriggerSkill{
  name = "efengqi__kurou",
  anim_type = "support",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      return data.from and not data.from.dead and not data.from.chained
    end
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name, nil, "#efengqi__kurou-ask:"..data.from.id.."::"..player:getLostHp()) then
      self.cost_data = {tos = {data.from.id}}
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = data.from
    to:drawCards(2, self.name)
    if not to.dead and not to.chained then
      to:setChainState(true)
    end
    if not to.dead then
      room:setPlayerMark(to, "@efengqi__kurou", tostring(player:getLostHp()))
    end
  end,
}
local kurou_targetmod = fk.CreateTargetModSkill{
  name = "#efengqi__kurou_targetmod",
  fix_times_func = function (self, player, skill, scope, card, to)
    if player and skill and scope and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      local mark = player:getMark("@efengqi__kurou")
      if mark ~= 0 then
        return tonumber(mark)
      end
    end
  end,
}
kurou:addRelatedSkill(kurou_targetmod)
huanggai:addSkill(kurou)

Fk:loadTranslationTable{
  ["efengqi__huanggai"] = "黄盖",
  ["#efengqi__huanggai"] = "燎发摧枯",
  ["designer:efengqi__huanggai"] = "白驹",
  ["illustrator:efengqi__huanggai"] = "",

  ["efengqi__zhaxiang"] = "诈降",
  [":efengqi__zhaxiang"] = "出牌阶段限一次，你可以令一名角色摸一张牌，然后视为对其使用一张【火攻】，若你因此受到伤害，重置此技能。",
  ["#efengqi__zhaxiang"] = "诈降：令一名角色摸一张牌，视为对其使用【火攻】",
  
  ["efengqi__kurou"] = "苦肉",
  [":efengqi__kurou"] = "当你受到伤害后，你可以令伤害来源摸两张牌并横置，且其本回合【杀】次数上限改为你此时已损失体力值。",
  ["#efengqi__kurou-ask"] = "苦肉：你可以令 %src 摸两张牌并横置，且【杀】次数上限改为 %arg",
  ["@efengqi__kurou"] = "苦肉",

  ["$efengqi__zhaxiang1"] = "铁锁连舟而行，东吴水师可破！",
  ["$efengqi__zhaxiang2"] = "两军阵前，不斩降将！",
  ["~efengqi__huanggai"] = "盖，有负公瑾重托……",
}

local zhouyu = General(extension, "efengqi__zhouyu", "wu", 3)

local yanshen = fk.CreateTriggerSkill{
  name = "efengqi__yanshen",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart, fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player == target then
      if event == fk.EventPhaseStart then
        if player.phase == Player.Draw then
          local card = Fk:cloneCard("fire_attack")
          card.skillName = self.name
          return player:canUse(card) and not player:prohibitUse(card)
          and table.find(player.room.alive_players, function (p)
            return not p:isKongcheng()
          end)
        end
      else
        return data.card and table.contains(data.card.skillNames, self.name)
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.DamageInflicted then return true end
    return player.room:askForSkillInvoke(player, self.name, nil, "#efengqi__yanshen-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted then
      player:drawCards(2, self.name)
    else
      for i = 1, 3 do
        local use = U.askForUseVirtualCard(room, player, "fire_attack", nil, self.name, "#efengqi__yanshen-use:::"..i, false, true)
        if not use then break end
      end
    end
    return true
  end,
}
zhouyu:addSkill(yanshen)

local guqu = fk.CreateActiveSkill{
  name = "efengqi__guqu",
  anim_type = "offensive",
  prompt = "#efengqi__guqu",
  card_num = 0,
  target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and Self.id ~= to_select and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    to:showCards(to:getCardIds("h"))
    room:delay(600)
    local suitMap = {}
    for _, id in ipairs(to:getCardIds("he")) do
      local suit = Fk:getCardById(id):getSuitString(true)
      if suitMap[suit] == nil then
        suitMap[suit] = {id}
      else
        table.insert(suitMap[suit], id)
      end
    end
    local suits, cardList = {}, {}
    for suit, ids in pairs(suitMap) do
      table.insert(suits, suit)
      table.insert(cardList, ids)
    end
    local names = U.askForChooseCardList(room, player, suits, cardList, 1, 1, self.name, "#efengqi__guqu-throw", false, true)
    if #names > 0 then
      room:throwCard(suitMap[names[1]], self.name, to, player)
      if not to.dead and not player.dead then
        if room:askForSkillInvoke(to, self.name, nil, "#efengqi__guqu-losehp:"..player.id) then
          room:loseHp(player, 1, self.name)
        end
      end
    else
      local suitsToGive, give = {}, {}
      for _, id in ipairs(player:getCardIds("he")) do
        local suit = Fk:getCardById(id):getSuitString(true)
        if not table.contains(suits, suit) then
          if table.insertIfNeed(suitsToGive, suit) then
            table.insert(give, id)
          end
        end
      end
      if #suitsToGive == 0 or #suitsToGive < (4 - #suits) then return end
      local str = table.concat(table.map(suitsToGive, function (s) return Fk:translate(s) end), ", ")
      local _,dat = room:askForUseActiveSkill(player, "efengqi__guqu_active", "#efengqi__guqu-give:"..to.id.."::"..str, false, {suits = suitsToGive})
      if dat then
        give = dat.cards
      end
      room:obtainCard(to, give, true, fk.ReasonGive, player.id, self.name)
      if not to.dead and not player.dead then
        if room:askForSkillInvoke(player, self.name, nil, "#efengqi__guqu-losehp:"..to.id) then
          room:loseHp(to, 1, self.name)
        end
      end
    end
  end,
}
zhouyu:addSkill(guqu)
local guqu_active = fk.CreateActiveSkill{
  name = "efengqi__guqu_active",
  card_num = function (self)
    return #self.suits
  end,
  target_num = 0,
  card_filter = function(self, to_select, selected)
    local suit = Fk:getCardById(to_select):getSuitString(true)
    return #selected < #self.suits and table.contains(self.suits, suit)
    and table.every(selected, function (id) return Fk:getCardById(id):getSuitString(true) ~= suit end)
  end,
}
Fk:addSkill(guqu_active)

Fk:loadTranslationTable{
  ["efengqi__zhouyu"] = "周瑜",
  ["#efengqi__zhouyu"] = "烈曲鸣江",
  ["designer:efengqi__zhouyu"] = "Z&白驹",
  ["illustrator:efengqi__zhouyu"] = "小新",

  ["efengqi__yanshen"] = "炎神",
  [":efengqi__yanshen"] = "摸牌阶段，你可以改为视为使用三张【火攻】，你因此受到伤害时改为摸两张牌。",
  ["#efengqi__yanshen-invoke"] = "炎神：你可以将摸牌阶段改为视为使用三张【火攻】",
  ["#efengqi__yanshen-use"] = "炎神：视为使用三张【火攻】（第 %arg 张），你受到此牌伤害时改为摸两张牌",

  ["efengqi__guqu"] = "顾曲",
  [":efengqi__guqu"] = "出牌阶段限一次，你可以展示一名其他角色的手牌并选一项：1.弃置其一种花色所有牌；2.交给其缺少花色各一张牌；你或其以此法失去牌后，可令对方失去一点体力。",
  ["#efengqi__guqu"] = "顾曲：展示一名其他角色的手牌，选择弃置其中牌，或交给其牌令其失去体力",
  ["#efengqi__guqu-throw"] = "顾曲：弃置其一种花色所有牌",
  ["#efengqi__guqu-losehp"] = "顾曲：选确定让 %src 失去1点体力",
  ["efengqi__guqu_active"] = "顾曲",
  ["#efengqi__guqu-give"] = "顾曲：你须交给 %src %arg 花色各一张牌",

  ["$efengqi__guqu1"] = "曲有误，不可不顾。",
  ["$efengqi__guqu2"] = "兀音曳绕梁，愿君去芜存菁。",
  ["$efengqi__yanshen1"] = "火莲绽江矶，炎映三千弱水。",
  ["$efengqi__yanshen2"] = "星火乘风，风助火势，其必成燎原之姿。",
  ["~efengqi__zhouyu"] = "既生瑜，何生……",
}

--[[
local zhouyu = General(extension, "efengqi__zhouyu", "wu", 3)
local yingzi = fk.CreateTriggerSkill{
  name = "efengqi__yingzi",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.from ~= player.id and move.moveReason == fk.ReasonUse then
          for _, info in ipairs(move.moveInfo) do
            if info.extra_data and info.extra_data.efengqi__yingziCheck then
              return true
            end
          end
        end
      end
    end
  end,
  on_trigger = function (self, event, target, player, data)
    local n = 0
    for _, move in ipairs(data) do
      if move.from ~= player.id and move.moveReason == fk.ReasonUse then
        for _, info in ipairs(move.moveInfo) do
          if info.extra_data and info.extra_data.efengqi__yingziCheck then
            n = n + 1
          end
        end
      end
    end
    for _ = 1, n, 1 do
      if not player:hasSkill(self) then return end
      self:doCost(event, target, player, data)
    end
  end,
  on_use = function (self, event, target, player, data)
    player:drawCards(1, self.name)
  end,

  refresh_events = {fk.DrawInitialCards, fk.AfterDrawInitialCards, fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.DrawInitialCards then
        return true
      elseif event == fk.AfterDrawInitialCards then
        return target ~= player and not target:isKongcheng()
      end
    end
    if event == fk.AfterCardsMove and player.seat == 1 then
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonUse then
          return true
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    if event == fk.DrawInitialCards then
      if target == player then
        data.num = 0
        player:broadcastSkillInvoke(self.name)
        player.room:notifySkillInvoked(player, self.name, "negative")
      else
        data.num = data.num + 1
      end
    elseif event == fk.AfterDrawInitialCards then
      local room = player.room
      for _, id in ipairs(target:getCardIds("h")) do
        room:setCardMark(Fk:getCardById(id), "@@efengqi__yingzi", 1)
      end
    elseif event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonUse then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Player.Hand and Fk:getCardById(info.cardId):getMark("@@efengqi__yingzi") ~= 0 then
              info.extra_data = info.extra_data or {}
              info.extra_data.efengqi__yingziCheck = true
              player.room:setCardMark(Fk:getCardById(info.cardId), "@@efengqi__yingzi", 0)
            end
          end
        end
      end
    end
  end,
}
zhouyu:addSkill(yingzi)

---@return integer[]
local getGuyinCard = function ()
  local room = Fk:currentRoom()
  return table.filter(room:getBanner("efengqi__guyin_card") or {}, function(id)
    return room:getCardArea(id) == Card.DiscardPile
  end)
end

local efengqi__guyin = fk.CreateViewAsSkill{
  name = "efengqi__guyin",
  pattern = ".",
  prompt = "#efengqi__guyin",
  expand_pile = function () return getGuyinCard() end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and table.contains(getGuyinCard(), to_select)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    return Fk:getCardById(cards[1])
  end,
  after_use = function (self, player, use)
    local room = player.room
    if room:getCardArea(use.card) == Card.DiscardPile then
      room:moveCards {
        ids = Card:getIdList(use.card),
        toArea = Card.DrawPile,
        moveReason = fk.ReasonJustMove,
        skillName = self.name,
        moveVisible = true,
        drawPilePosition = math.random(#room.draw_pile+1),
      }
    end
  end,
  enabled_at_play = function(self, player)
    return true
  end,
  enabled_at_response = function (self, player, response)
    if not response and Fk.currentResponsePattern then
      return table.find(getGuyinCard(), function(id)
        return Exppattern:Parse(Fk.currentResponsePattern):match(Fk:getCardById(id))
      end) ~= nil
    end
  end,
}

local efengqi__guyin_trigger = fk.CreateTriggerSkill{
  name = "#efengqi__guyin_trigger",
  anim_type = "support",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target ~= player and not target.dead and not target:isKongcheng() then
      return target:getMark(self.name) == 0
    end
  end,
  on_cost = function (self, event, target, player, data)
    local cards = player.room:askForCard(target, 1, 1, false, self.name, true, ".", "#efengqi__guyin-card:"..player.id)
    if #cards > 0 then
      self.cost_data = {cards = cards, tos = {target.id}}
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(target, self.name, 1)
    local card = Fk:getCardById(self.cost_data.cards[1])
    room:setCardMark(card, "@@efengqi__guyin", 1)
    local banner = room:getBanner("efengqi__guyin_card") or {}
    table.insertIfNeed(banner, card.id)
    room:setBanner("efengqi__guyin_card", banner)
    room:recover { num = 1, skillName = "efengqi__guyin", who = target, recoverBy = player }
  end,
}
efengqi__guyin:addRelatedSkill(efengqi__guyin_trigger)

zhouyu:addSkill(efengqi__guyin)

Fk:loadTranslationTable{
  ["efengqi__zhouyu"] = "周瑜",
  ["#efengqi__zhouyu"] = "",
  ["designer:efengqi__zhouyu"] = "",
  ["illustrator:efengqi__zhouyu"] = "小新",

  ["efengqi__yingzi"] = "英姿",
  [":efengqi__yingzi"] = "锁定技，你没有初始手牌，其他角色的初始手牌+1。其他角色因使用而失去一张初始手牌时，你摸一张牌。",
  ["@@efengqi__yingzi"] = "英姿",

  ["efengqi__guyin"] = "顾音",
  [":efengqi__guyin"] = "每名其他角色限一次，其他角色回合开始时，其可以将一张手牌标记为“顾”，然后其回复1点体力；你可以如手牌般使用弃牌堆中的“顾”，然后将之从弃牌堆洗入牌堆中。",
  ["#efengqi__guyin-card"] = "顾音：你可以将一张手牌标记为“顾”，然后回复1点体力",
  ["#efengqi__guyin_trigger"] = "顾音",
  ["@@efengqi__guyin"] = "顾",
  ["#efengqi__guyin"] = "顾音：你可以如手牌般使用弃牌堆中的“顾”！",

  ["$efengqi__yingzi1"] = "哈哈哈哈……",
  ["$efengqi__yingzi2"] = "汝等看好了！",
  ["$efengqi__fanjian1"] = "挣扎吧，在血和暗的深渊里！",
  ["$efengqi__fanjian2"] = "痛苦吧，在仇与恨的地狱中！",
  ["~efengqi__zhouyu"] = "既生瑜，何生……",
}
--]]
local daqiao = General(extension, "efengqi__daqiao", "wu", 3, 3, General.Female)

local qiqin = fk.CreateTriggerSkill{
  name = "efengqi__qiqin",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.GameStart, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if event == fk.GameStart then
      return player:hasSkill(self) and not player:isKongcheng()
    elseif player:hasSkill(self) and target == player and player.phase == Player.Play then
      local get = table.filter(player.room:getBanner("efengqi__qiqin_record") or {}, function(id)
        return not table.contains(player:getCardIds("h"), id)
      end)
      if #get > 0 then
        self.cost_data = get
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      local cards = player:getCardIds(Player.Hand)
      for _, id in ipairs(cards) do
        room:setCardMark(Fk:getCardById(id), "@@efengqi__qiqin", 1)
      end
      local record = room:getBanner("efengqi__qiqin_record") or {}
      table.insertTableIfNeed(record, cards)
      room:setBanner("efengqi__qiqin_record", record)
    else
      room:moveCardTo(self.cost_data, Player.Hand, player, fk.ReasonJustMove, self.name, "", false, player.id)
    end
  end,
}
local qiqin_maxcards = fk.CreateMaxCardsSkill{
  name = "#efengqi__qiqin_maxcards",
  exclude_from = function(self, player, card)
    return card and card:getMark("@@efengqi__qiqin") ~= 0 and player:hasSkill(qiqin)
  end,
}

qiqin:addRelatedSkill(qiqin_maxcards)
daqiao:addSkill(qiqin)

local zixi = fk.CreateTriggerSkill{
  name = "efengqi__zixi",
  anim_type = "support",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if not target.dead and player:hasSkill(self) then
      return not player:isKongcheng() and not table.contains(target.sealedSlots, Player.JudgeSlot)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local ids = table.filter(player:getCardIds("he"), function(id) return Fk:getCardById(id):getMark("@@efengqi__qiqin") ~= 0 end)
    local cards = player.room:askForCard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = ids }),
    "#efengqi__zixi-invoke:"..target.id)
    if #cards > 0 then
      self.cost_data = {cards = cards, tos = {target.id}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cid = self.cost_data.cards[1]
    local card = Fk:cloneCard("indulgence")
    card:addSubcard(cid)
    target:addVirtualEquip(card)
    room:moveCardTo(cid, Player.Judge, target, fk.ReasonJustMove, self.name)
    if target.dead then return end
    local get = table.filter(target:getCardIds("ej"), function (id)
      return Fk:getCardById(id).suit == Fk:getCardById(cid).suit
    end)
    if #get > 0 then
      room:delay(400)
      room:moveCardTo(get, Player.Hand, target, fk.ReasonJustMove, self.name, "", true, target.id)
    end
  end,
}
daqiao:addSkill(zixi)

Fk:loadTranslationTable{
  ["efengqi__daqiao"] = "大乔",
  ["#efengqi__daqiao"] = "",
  ["designer:efengqi__daqiao"] = "Romantic",
  ["illustrator:efengqi__daqiao"] = "",

  ["efengqi__qiqin"] = "绮琴",
  [":efengqi__qiqin"] = "锁定技，游戏开始时，将初始手牌标记为“琴”，“琴”不计入你的手牌上限；出牌阶段开始时，你获得所有“琴”。",
  ["@@efengqi__qiqin"] = "琴",

  ["efengqi__zixi"] = "姊希",
  [":efengqi__zixi"] = "每回合开始时，你可以将一张“琴”置入当前回合角色的判定区，然后其获得其场上所有与此牌花色相同的牌。",
  ["#efengqi__zixi-invoke"] = "姊希：你可以将一张“琴”置入 %src 判定区，然后其获得其场上与之花色相同的牌",
}

--FY018 陆逊 by屑
local luxun = General(extension, "efengqi__luxun", "wu", 3)

local zhuying = fk.CreateViewAsSkill{
  name = "efengqi__zhuying",
  pattern = "fire_attack,nullification",
  mute = true,
  prompt = "#efengqi__zhuying",
  interaction = function(self)
    local all_names = {"fire_attack", "nullification"}
    local names = U.getViewAsCardNames(Self, self.name, all_names)
    if #names > 0 then
      return U.CardNameBox {choices = names, all_choices = all_names}
    end
  end,
  card_filter = function (self, to_select, selected)
    if Self:getHandcardNum() > 1 then
      return #selected < Self:getHandcardNum() - 1 and table.contains(Self:getCardIds("h"), to_select) and
        not Self:prohibitDiscard(to_select)
    else
      return false
    end
  end,
  view_as = function(self, cards)
    if Self:getHandcardNum() > 1 then
      if #cards ~= Self:getHandcardNum() - 1 then return end
      self.cost_data = cards
    elseif Self:getHandcardNum() == 0 then
      if #cards > 0 then return end
      self.cost_data = nil
    end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  before_use = function (self, player, use)
    local room = player.room
    if self.interaction.data == "fire_attack" then
      player:broadcastSkillInvoke(self.name, table.random({1, 2}))
      room:notifySkillInvoked(player, self.name, "offensive")
    else
      player:broadcastSkillInvoke(self.name, table.random({3, 4}))
      room:notifySkillInvoked(player, self.name, "control")
    end
    if self.cost_data then
      room:throwCard(self.cost_data, self.name, player, player)
    else
      player:drawCards(1, self.name)
    end
  end,
  enabled_at_play = function(self, player)
    return player:getHandcardNum() ~= 1
  end,
  enabled_at_response = function(self, player, response)
    return not response and player:getHandcardNum() ~= 1
  end,
}
luxun:addSkill(zhuying)
local qianxun = fk.CreateProhibitSkill{
  name = "efengqi__qianxun",
  frequency = Skill.Compulsory,
  is_prohibited = function(self, from, to, card)
    if to:hasSkill(self) then
      return card.name == "indulgence" or card.name == "snatch"
    end
  end,
}
luxun:addSkill(qianxun)
Fk:loadTranslationTable{
  ["efengqi__luxun"] = "陆逊",
  ["#efengqi__luxun"] = "剑照儒纶",
  ["illustrator:efengqi__luxun"] = "官方",
  ["designer:efengqi__luxun"] = "屑",

  ["efengqi__zhuying"] = "烛营",
  [":efengqi__zhuying"] = "你可以将手牌数调整至1，视为使用【火攻】或【无懈可击】",
  ["#efengqi__zhuying"] = "烛营：你可以将手牌数调整至1，视为使用【火攻】或【无懈可击】",

  ["efengqi__qianxun"] = "谦逊",
  [":efengqi__qianxun"] = "锁定技，你不能被选择为【顺手牵羊】与【乐不思蜀】的目标。",

  ["$efengqi__zhuying1"] = "今提墨笔绘乾坤，湖海添色山永春。",
  ["$efengqi__zhuying2"] = "手提玉剑斥千军，昔日锦鲤化金龙。",
  ["~efengqi__luxun"] = "此生清白，不为浊泥所染。",
}

local sunshangxiang = General(extension, "efengqi__sunshangxiang", "wu", 3, 3, General.Female)
local xiaoji = fk.CreateTriggerSkill{
  name = "efengqi__xiaoji",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    local choices = {}
    local n = 0
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip then  --甚至比标准版还弱
            table.insertIfNeed(choices, 1)
          end
          if table.concat({Card.PlayerHand, Card.PlayerEquip}, info.fromArea) then
            n = n + 1
          end
        end
      end
    end
    if n > 1 then
      table.insert(choices, 2)
    end
    if #choices > 0 then
      self.cost_data = choices
      if table.contains(choices, 1) then
        return true
      else
        return table.find(player.room:getOtherPlayers(player), function (p)
          return p:isWounded()
        end)
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    if table.contains(self.cost_data, 1) then
      player:drawCards(2, self.name)
      if player.dead or not table.contains(self.cost_data, 2) then return end
    end
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player), function (p)
      return p:isWounded()
    end)
    if #targets == 0 then return end
    local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#efengqi__xiaoji-invoke", self.name, true)
    if #to > 0 then
      to = room:getPlayerById(to[1])
      room:recover{
        who = to,
        num = 1,
        recoverBy = player,
        skillName = self.name
      }
      if player:isWounded() and not player.dead then
        room:recover{
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name
        }
      end
    end
  end,
}
local jieyin = fk.CreateViewAsSkill{
  name = "efengqi__jieyin",
  anim_type = "support",
  prompt = "#efengqi__jieyin",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local c = Fk:cloneCard("sincere_treat")
    c.skillName = self.name
    return c
  end,
  enabled_at_play = function (self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
}
local jieyin_targetmod = fk.CreateTargetModSkill{
  name = "#efengqi__jieyin_targetmod",
  bypass_distances =  function(self, player, skill, card, to)
    return card and table.contains(card.skillNames, "efengqi__jieyin") and to and to:isMale()
  end,
}
jieyin:addRelatedSkill(jieyin_targetmod)
sunshangxiang:addSkill(xiaoji)
sunshangxiang:addSkill(jieyin)
Fk:loadTranslationTable{
  ["efengqi__sunshangxiang"] = "孙尚香",
  ["#efengqi__sunshangxiang"] = "弓腰姬",
  ["illustrator:efengqi__sunshangxiang"] = "君桓文化",
  ["designer:efengqi__sunshangxiang"] = "老猫",

  ["efengqi__xiaoji"] = "枭姬",
  [":efengqi__xiaoji"] = "当你失去：装备区中的牌后，摸两张牌；至少两张牌后，你可以与一名其他角色各回复1点体力。",
  ["efengqi__jieyin"] = "结姻",
  [":efengqi__jieyin"] = "出牌阶段限一次，你可以视为使用【推心置腹】，此牌对男性角色使用无距离限制。",
  ["#efengqi__xiaoji-invoke"] = "枭姬：你可以与一名其他角色各回复1点体力",
  ["#efengqi__jieyin"] = "结姻：你可以视为使用【推心置腹】",

  ["$efengqi__jieyin1"] = "随夫嫁娶，宜室宜家。",
  ["$efengqi__jieyin2"] = "得遇夫君，妾身福分。",
  ["$efengqi__xiaoji1"] = "剑利弓急，你可打不过我的。",
  ["$efengqi__xiaoji2"] = "我会的武器，可多着呢。",
  ["~efengqi__sunshangxiang"] = "哎呀，这次弓箭射歪了。",
}


local huatuo = General(extension, "efengqi__huatuo", "qun", 3)

local chuli = fk.CreateActiveSkill{
  name = "efengqi__chuli",
  anim_type = "control",
  card_num = 1,
  target_num = 0,
  prompt = "#efengqi__chuli",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).suit == Card.Club
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:recastCard(effect.cards, player, self.name)
    if player.dead then return end
    local n, drawer = 4, {}
    -- 滕芳兰式弃牌，任意角色共计4张
    while n > 0 and player:isAlive() do
      local targets = table.filter(room.alive_players, function (p) return not p:isNude() end)
      if #targets == 0 then break end
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper),
      1, 1, "#efengqi__chuli-choose:::"..n, self.name, false)
      if #tos == 0 then break end
      local to = room:getPlayerById(tos[1])
      local cards = room:askForCardsChosen(player, to, 1, n, "he", self.name)
      n = n - #cards
      if table.find(cards, function (id) return Fk:getCardById(id).suit == Card.Spade end) then
        table.insertIfNeed(drawer, to.id)
      end
      room:throwCard(cards, self.name, to, player)
    end
    if #drawer > 0 then
      room:delay(300)
      room:sortPlayersByAction(drawer)
      room:doIndicate(player.id, drawer)
      for _, pid in ipairs(drawer) do
        local p = room:getPlayerById(pid)
        if not p.dead then
          local num = p.maxHp - p:getHandcardNum()
          if num > 0 then
            p:drawCards(num, self.name)
          end
        end
      end
    end
  end,
}
huatuo:addSkill(chuli)

local qingnang = fk.CreateViewAsSkill{
  name = "efengqi__qingnang",
  pattern = "peach,drugs",
  prompt = "#efengqi__qingnang",
  anim_type = "support",
  card_filter = function(self, to_select, selected, player)
    if #selected > 0 then return false end
    local suit = Fk:getCardById(to_select).suit
    local c
    if suit == Card.Heart then
      c = Fk:cloneCard("peach")
    elseif suit == Card.Diamond then
      c = Fk:cloneCard("drugs")
    else
      return false
    end
    c.skillName = self.name
    return (Fk.currentResponsePattern == nil and player:canUse(c) and not player:prohibitUse(c))
    or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(c))
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local c = Fk:cloneCard(Fk:getCardById(cards[1]).suit == Card.Heart and "peach" or "drugs")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}
huatuo:addSkill(qingnang)

Fk:loadTranslationTable{
  ["efengqi__huatuo"] = "华佗",
  ["#efengqi__huatuo"] = "治世医骨",
  ["designer:efengqi__huatuo"] = "zzcclll朱苦力",
  ["illustrator:efengqi__huatuo"] = "聚一",

  ["efengqi__chuli"] = "除疠",
  [":efengqi__chuli"] = "出牌阶段限一次，你可以重铸一张♣牌，然后弃置任意名角色共四张牌，因此失去♠牌的角色摸牌至体力上限。",
  ["#efengqi__chuli"] = "除疠：重铸一张♣牌，弃置任意名角色共四张牌",
  ["#efengqi__chuli-choose"] = "除疠：选择一名角色，弃置其至多 %arg 张牌",

  ["efengqi__qingnang"] = "青囊",
  [":efengqi__qingnang"] = "你可以将一张<font color='red'>♥</font>牌当【桃】使用；或将一张<font color='red'>♦</font>牌当【散】使用。",
  ["#efengqi__qingnang"] = "青囊：将<font color='red'>♥</font>牌当【桃】使用；将<font color='red'>♦</font>牌当【散】使用",

  ["$efengqi__qingnang1"] = "救死扶伤，悬壶济世。",
  ["$efengqi__qingnang2"] = "妙手仁心，药到病除。",
  ["$efengqi__chuli1"] = "病去，如抽丝。",
  ["$efengqi__chuli2"] = "病入膏肓，需下猛药。",
  ["~efengqi__huatuo"] = "生老病死，命不可违。",
}

local diaochan = General(extension, "efengqi__diaochan", "han", 3, 3, General.Female)

local lijian = fk.CreateActiveSkill{
  name = "efengqi__lijian",
  anim_type = "control",
  card_num = 1,
  target_num = 2,
  prompt = "#efengqi__lijian",
  card_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  target_tip = function (self, to_select, selected, selected_cards, card, selectable, extra_data)
    if #selected > 0 then
      if to_select == selected[1] then
        return "@efengqi__lijian_first"
      elseif to_select == selected[2] then
        return { {content = "@efengqi__lijian_last", type = "warning"} }
      end
    end
  end,
  target_filter = function (self, to_select, selected, cards)
    local to = Fk:currentRoom():getPlayerById(to_select)
    if #selected < 2 and Self.id ~= to_select and #cards > 0 then
      local duel = Fk:cloneCard("duel")
      duel.skillName = self.name
      if #selected == 0 then
        return not to:prohibitUse(duel)
      else
        return not Fk:currentRoom():getPlayerById(selected[1]):isProhibited(to, duel)
      end
    end
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to1, to2 = room:getPlayerById(effect.tos[1]), room:getPlayerById(effect.tos[2])
    local cards = effect.cards
    player:showCards(cards)
    local use = room:useVirtualCard("duel", nil, to1, to2, self.name)
    if not use then return end
    local winner, loser
    if use.damageDealt then
      if use.damageDealt[to2.id] then
        winner, loser = to1, to2
      elseif use.damageDealt[to1.id] then
        winner, loser = to2, to1
      end
    end
    if winner and winner:isAlive() then
      if room:getCardOwner(cards[1]) == player or room:getCardArea(cards[1]) == Card.DiscardPile then
        room:obtainCard(winner, cards, true, fk.ReasonPrey, winner.id, self.name)
      end
    end
    if loser and not loser:isNude() and not player.dead then
      local cid = room:askForCardChosen(player, loser, "he", self.name)
      room:obtainCard(player, cid, true, fk.ReasonPrey, player.id, self.name)
    end
  end,
}
diaochan:addSkill(lijian)

local biyue = fk.CreateTriggerSkill{
  name = "efengqi__biyue",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
    and table.find({"h","e","j"}, function(flag) return #player:getCardIds(flag) == 0 end)
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(#table.filter({"h","e","j"}, function(flag) return #player:getCardIds(flag) == 0 end), self.name)
  end,
}
diaochan:addSkill(biyue)

Fk:loadTranslationTable{
  ["efengqi__diaochan"] = "貂蝉",
  ["#efengqi__diaochan"] = "暮阳染玉",
  ["designer:efengqi__diaochan"] = "zzcclll朱苦力",
  ["illustrator:efengqi__diaochan"] = "空山",

  ["efengqi__lijian"] = "离间",
  [":efengqi__lijian"] = "出牌阶段限一次，你可以选择两名其他角色并展示一张牌，令前者视为对后者使用【决斗】，赢者获得你展示牌，你获得败者一张牌。",
  ["#efengqi__lijian"] = "离间：展示一张牌，令两名角色决斗，赢者获得展示牌",
  ["@efengqi__lijian_first"] = "使用者",
  ["@efengqi__lijian_last"] = "被决斗",

  ["efengqi__biyue"] = "闭月",
  [":efengqi__biyue"] = "锁定技，结束阶段，你每有一个区域没有牌，便摸一张牌。",

  ["$efengqi__lijian1"] = "嗯呵呵～～呵呵～～",
  ["$efengqi__lijian2"] = "夫君，你要替妾身作主啊~",
  ["$efengqi__biyue1"] = "失礼了～",
  ["$efengqi__biyue2"] = "羡慕吧～",
  ["~efengqi__diaochan"] = "父亲大人，对不起……",
}



return extension
